Prompt specification
Build or customize the Three.js 3D scene "Succulent leaf storage 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: Succulent leaf storage section
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/succulent-leaf-storage-section-x0793
Scene Description Prompt:
Compare a stylized succulent leaf storage cutaway with a thin leaf, distinguishing skin from interior tissue. Three.js from cdnjs, one HTML file.
Working Three.js Starter (succulent-leaf-storage-section-x0793):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Succulent vs. Thin Leaf — Three.js Cutaway</title>
<style>
:root {
--ink: #17372f;
--muted: #63736b;
--paper: #f3f0e7;
--skin: #24634e;
--storage: #a8ca69;
--mesophyll: #7eb38a;
--vascular: #c89045;
--line: rgba(27, 65, 53, 0.22);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 38%, rgba(45, 65, 52, 0.055) 100%);
z-index: 1;
}
.interface {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
header {
position: absolute;
top: clamp(22px, 4vw, 48px);
left: clamp(22px, 4vw, 56px);
width: min(560px, calc(100vw - 44px));
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: #5e7469;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 30px;
height: 1px;
content: "";
background: #6e8a79;
}
h1 {
max-width: 540px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4.5vw, 64px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.045em;
}
.intro {
max-width: 460px;
margin: 18px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
}
.legend {
position: absolute;
top: clamp(22px, 4vw, 44px);
right: clamp(22px, 4vw, 48px);
display: grid;
grid-template-columns: repeat(2, auto);
gap: 10px 22px;
padding: 15px 17px;
border: 1px solid rgba(50, 82, 67, 0.13);
border-radius: 13px;
background: rgba(249, 248, 242, 0.68);
box-shadow: 0 10px 30px rgba(40, 60, 47, 0.05);
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #53685e;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.skin {
background: var(--skin);
}
.swatch.storage {
background: var(--storage);
}
.swatch.mesophyll {
background: var(--mesophyll);
}
.swatch.vascular {
background: var(--vascular);
}
.controls {
position: absolute;
right: clamp(22px, 4vw, 48px);
bottom: 164px;
display: flex;
gap: 7px;
pointer-events: auto;
}
.control {
min-height: 34px;
padding: 0 12px;
border: 1px solid rgba(42, 73, 59, 0.16);
border-radius: 999px;
background: rgba(250, 249, 244, 0.8);
color: #52665d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.03em;
cursor: pointer;
backdrop-filter: blur(10px);
transition:
background 160ms ease,
color 160ms ease,
transform 160ms ease;
}
.control:hover {
transform: translateY(-1px);
background: #fffdf6;
color: var(--ink);
}
.control.active {
border-color: #315f4d;
background: #315f4d;
color: #fffdf4;
}
.comparison {
position: absolute;
right: clamp(22px, 4vw, 48px);
bottom: 22px;
left: clamp(22px, 4vw, 48px);
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
max-width: 850px;
pointer-events: auto;
}
.info-card {
min-height: 120px;
padding: 17px 19px;
border: 1px solid rgba(45, 78, 62, 0.14);
border-radius: 15px;
background: rgba(250, 249, 244, 0.83);
box-shadow: 0 14px 40px rgba(46, 64, 51, 0.06);
backdrop-filter: blur(14px);
}
.info-top {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
margin-bottom: 10px;
}
.info-card h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
letter-spacing: -0.02em;
}
.info-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.trait {
color: #426456;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
}
.trait::before {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
content: "";
background: var(--storage);
}
.thin .trait::before {
background: var(--mesophyll);
}
#leaders {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
stroke: rgba(35, 73, 57, 0.55);
stroke-width: 1;
stroke-dasharray: 2 3;
vector-effect: non-scaling-stroke;
}
#leaders circle {
fill: #f8f6ef;
stroke: #315f4d;
stroke-width: 1.5;
vector-effect: non-scaling-stroke;
}
.callout {
position: absolute;
z-index: 4;
min-width: 116px;
padding: 9px 11px 10px;
border: 1px solid rgba(39, 74, 58, 0.18);
border-radius: 9px;
background: rgba(252, 251, 246, 0.91);
box-shadow: 0 8px 24px rgba(41, 59, 47, 0.08);
color: #24483a;
font-size: 10px;
font-weight: 800;
line-height: 1.25;
text-align: center;
transform: translate(-50%, -50%);
backdrop-filter: blur(10px);
transition: opacity 180ms ease;
}
.callout small {
display: block;
margin-top: 3px;
color: #78877f;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.callout.storage {
border-top: 3px solid var(--storage);
}
.callout.mesophyll {
border-top: 3px solid var(--mesophyll);
}
.callout.skin {
border-top: 3px solid var(--skin);
}
.annotations-hidden .callout,
.annotations-hidden #leaders {
opacity: 0;
}
.hint {
position: absolute;
bottom: 26px;
left: clamp(22px, 4vw, 56px);
color: #7a887f;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--paper);
color: #527164;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.legend {
grid-template-columns: 1fr;
}
.comparison {
max-width: none;
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
header {
top: 19px;
}
h1 {
max-width: 320px;
font-size: 36px;
}
.intro {
max-width: 310px;
margin-top: 12px;
font-size: 11px;
}
.legend {
top: 18px;
right: 16px;
display: none;
}
.comparison {
right: 12px;
bottom: 12px;
left: 12px;
gap: 7px;
}
.info-card {
min-height: 116px;
padding: 13px;
}
.info-top {
display: block;
}
.info-card h2 {
font-size: 17px;
}
.trait {
display: block;
margin-top: 5px;
font-size: 8px;
}
.info-card p {
font-size: 10px;
}
.controls {
right: 12px;
bottom: 157px;
}
.control {
padding: 0 9px;
font-size: 9px;
}
.callout {
min-width: 92px;
padding: 7px 8px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive three-dimensional comparison of a succulent storage leaf and a thin leaf"
></canvas>
<div class="vignette"></div>
<div class="interface">
<header>
<div class="eyebrow">Botanical anatomy / 01</div>
<h1>One leaf.<br>Two strategies.</h1>
<p class="intro">
A longitudinal cutaway compares the thick, water-storing interior of a
succulent with the compact tissue of a thin exchange leaf.
</p>
</header>
<aside class="legend" aria-label="Tissue color legend">
<div class="legend-item">
<span class="swatch skin"></span>
Epidermal skin
</div>
<div class="legend-item">
<span class="swatch storage"></span>
Storage tissue
</div>
<div class="legend-item">
<span class="swatch mesophyll"></span>
Mesophyll
</div>
<div class="legend-item">
<span class="swatch vascular"></span>
Vascular tissue
</div>
</aside>
<svg id="leaders" aria-hidden="true"></svg>
<div class="controls">
<button class="control active" id="rotateButton" type="button">
Auto rotate
</button>
<button class="control" id="labelsButton" type="button">
Labels
</button>
<button class="control" id="resetButton" type="button">
Reset
</button>
</div>
<section class="comparison" aria-label="Leaf comparison">
<article class="info-card">
<div class="info-top">
<h2>Succulent / storage leaf</h2>
<span class="trait">High water capacity</span>
</div>
<p>
A protective outer skin encloses broad, water-rich parenchyma.
The thick interior stores resources and supports the leaf.
</p>
</article>
<article class="info-card thin">
<div class="info-top">
<h2>Thin / exchange leaf</h2>
<span class="trait">High exchange rate</span>
</div>
<p>
A thin epidermis covers compact mesophyll and a branching vascular
network, keeping the distance for gas and water transfer short.
</p>
</article>
</section>
<div class="hint">Drag to orbit · Scroll or pinch to zoom</div>
</div>
<div id="loading">Preparing cutaway</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const leaders = document.querySelector("#leaders");
const labelsButton = document.querySelector("#labelsButton");
const rotateButton = document.querySelector("#rotateButton");
const resetButton = document.querySelector("#resetButton");
const renderer = new THREE.WebGLRenderer({
canvas,
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf3f0e7);
scene.fog = new THREE.Fog(0xf3f0e7, 16, 30);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xfffbef, 0x7d8d78, 2.1);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff3d7, 3.5);
key.position.set(-4, 8, 6);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -9;
key.shadow.camera.right = 9;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 1;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0004;
scene.add(key);
const fill = new THREE.DirectionalLight(0xb9d8df, 1.6);
fill.position.set(7, 3, -7);
scene.add(fill);
const rimLight = new THREE.PointLight(0xe3f0c8, 14, 18, 2);
rimLight.position.set(0, 3, -4);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe8e5da,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 22),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.26;
ground.receiveShadow = true;
scene.add(ground);
const pedestalMaterial = new THREE.MeshStandardMaterial({
color: 0xf8f5eb,
roughness: 0.78,
metalness: 0
});
const pedestalEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xcfd6c8,
roughness: 0.85
});
function addPedestal(x) {
const group = new THREE.Group();
const base = new THREE.Mesh(
new THREE.CylinderGeometry(2.48, 2.64, 0.17, 96),
pedestalEdgeMaterial
);
base.position.y = -1.16;
base.receiveShadow = true;
group.add(base);
const top = new THREE.Mesh(
new THREE.CylinderGeometry(2.45, 2.45, 0.075, 96),
pedestalMaterial
);
top.position.y = -1.045;
top.receiveShadow = true;
group.add(top);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(2.12, 0.012, 8, 100),
new THREE.MeshBasicMaterial({
color: 0xaab8a9,
transparent: true,
opacity: 0.42
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -1.002;
group.add(ring);
group.position.x = x;
scene.add(group);
}
addPedestal(-3.15);
addPedestal(3.15);
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0x24634e,
roughness: 0.48,
metalness: 0,
side: THREE.DoubleSide
});
const skinLightMaterial = new THREE.MeshStandardMaterial({
color: 0x39785c,
roughness: 0.52,
metalness: 0
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0x7e9d59,
roughness: 0.78,
metalness: 0,
side: THREE.DoubleSide
});
const storageMaterial = new THREE.MeshStandardMaterial({
color: 0xa8ca69,
roughness: 0.72,
metalness: 0,
side: THREE.DoubleSide
});
const mesophyllMaterial = new THREE.MeshStandardMaterial({
color: 0x7eb38a,
roughness: 0.8,
metalness: 0,
side: THREE.DoubleSide
});
const vascularMaterial = new THREE.MeshStandardMaterial({
color: 0xc89045,
roughness: 0.58,
metalness: 0.03
});
const lowerSkinMaterial = new THREE.MeshStandardMaterial({
color: 0x315d4c,
roughness: 0.58,
metalness: 0,
side: THREE.DoubleSide
});
/*
* Grid surfaces are built manually so rectangular portions can be removed
* from the epidermis while revealing the tissue underneath.
*/
function makeGridSurface({
uSegments,
vSegments,
position,
skip = () => false,
flip = false
}) {
const positions = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= uSegments; i++) {
const u = i / uSegments;
for (let j = 0; j <= vSegments; j++) {
const v = j / vSegments;
const p = position(u, v);
positions.push(p.x, p.y, p.z);
uvs.push(u, v);
}
}
const row = vSegments + 1;
for (let i = 0; i < uSegments; i++) {
for (let j = 0; j < vSegments; j++) {
const u = (i + 0.5) / uSegments;
const v = (j + 0.5) / vSegments;
if (skip(u, v)) continue;
const a = i * row + j;
const b = (i + 1) * row + j;
const c = (i + 1) * row + j + 1;
const d = i * row + j + 1;
if (flip) {
indices.push(a, b, d, b, c, d);
} else {
indices.push(a, d, b, b, d, c);
}
}
}
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();
geometry.computeBoundingSphere();
return geometry;
}
function makeQuadStrip(pointsA, pointsB) {
const positions = [];
const indices = [];
for (let i = 0; i < pointsA.length; i++) {
const a = pointsA[i];
const b = pointsB[i];
positions.push(a.x, a.y, a.z, b.x, b.y, b.z);
}
for (let i = 0; i < pointsA.length - 1; i++) {
const a = i * 2;
const b = i * 2 + 1;
const c = i * 2 + 2;
const d = i * 2 + 3;
indices.push(a, b, d, b, c, d);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function tubeFromPoints(points, radius, material, segments = 72) {
const curve = new THREE.CatmullRomCurve3(points);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 8, false),
material
);
mesh.castShadow = true;
return mesh;
}
/* ---------------- Succulent leaf ---------------- */
const succulentLength = 4.65;
function succulentProfile(u) {
const arch = Math.pow(Math.sin(Math.PI * u), 0.58);
return arch * (0.80 + 0.34 * u);
}
function succulentPoint(u, theta, scale = 1) {
const profile = succulentProfile(u);
const radiusY = 0.68 * profile * scale;
const radiusZ = 0.53 * profile * scale;
return new THREE.Vector3(
(u - 0.5) * succulentLength,
0.10 * Math.sin(Math.PI * u) + radiusY * Math.cos(theta),
radiusZ * Math.sin(theta)
);
}
const succulentGroup = new THREE.Group();
succulentGroup.position.set(-3.15, -0.02, 0);
succulentGroup.rotation.y = -0.035;
scene.add(succulentGroup);
const holeU0 = 0.205;
const holeU1 = 0.785;
const holeT0 = 0.62;
const holeT1 = 1.39;
const succulentShellGeometry = makeGridSurface({
uSegments: 88,
vSegments: 72,
position: (u, v) => succulentPoint(u, v * Math.PI * 2),
skip: (u, v) => {
const theta = v * Math.PI * 2;
return (
u > holeU0 &&
u < holeU1 &&
theta > holeT0 &&
theta < holeT1
);
}
});
const succulentShell = new THREE.Mesh(
succulentShellGeometry,
skinMaterial
);
succulentShell.castShadow = true;
succulentShell.receiveShadow = true;
succulentGroup.add(succulentShell);
const succulentCoreGeometry = makeGridSurface({
uSegments: 76,
vSegments: 60,
position: (u, v) => succulentPoint(u, v * Math.PI * 2, 0.84)
});
const succulentCore = new THREE.Mesh(
succulentCoreGeometry,
storageMaterial
);
succulentCore.castShadow = true;
succulentGroup.add(succulentCore);
function addSucculentRim(parameterA, parameterB) {
const outer = [];
const inner = [];
for (let i = 0; i <= 48; i++) {
const t = i / 48;
const u = parameterA.u + (parameterB.u - parameterA.u) * t;
const theta =
parameterA.theta + (parameterB.theta - parameterA.theta) * t;
outer.push(succulentPoint(u, theta));
inner.push(succulentPoint(u, theta, 0.84));
}
const rim = new THREE.Mesh(
makeQuadStrip(outer, inner),
cutMaterial
);
rim.castShadow = true;
succulentGroup.add(rim);
}
addSucculentRim(
{ u: holeU0, theta: holeT0 },
{ u: holeU0, theta: holeT1 }
);
addSucculentRim(
{ u: holeU1, theta: holeT0 },
{ u: holeU1, theta: holeT1 }
);
addSucculentRim(
{ u: holeU0, theta: holeT0 },
{ u: holeU1, theta: holeT0 }
);
addSucculentRim(
{ u: holeU0, theta: holeT1 },
{ u: holeU1, theta: holeT1 }
);
const ridgeAngles = [0.10, 0.34, 2.80, 3.02, 4.90, 5.18];
for (const angle of ridgeAngles) {
const points = [];
for (let i = 0; i <= 36; i++) {
const u = 0.055 + (i / 36) * 0.89;
const point = succulentPoint(u, angle);
point.y += 0.009 * Math.cos(angle);
point.z += 0.009 * Math.sin(angle);
points.push(point);
}
succulentGroup.add(
tubeFromPoints(points, 0.009, skinLightMaterial, 64)
);
}
const vascularPoints = [];
for (let i = 0; i <= 44; i++) {
const u = 0.075 + (i / 44) * 0.85;
vascularPoints.push(succulentPoint(u, 1.34, 0.85));
}
succulentGroup.add(
tubeFromPoints(vascularPoints, 0.022, vascularMaterial, 72)
);
const bubbleGeometry = new THREE.SphereGeometry(1, 12, 8);
const bubbleMaterial = new THREE.MeshPhysicalMaterial({
color: 0xe4efae,
roughness: 0.25,
transparent: true,
opacity: 0.56,
transmission: 0.08,
depthWrite: false
});
const bubbles = new THREE.InstancedMesh(
bubbleGeometry,
bubbleMaterial,
48
);
const bubbleDummy = new THREE.Object3D();
let randomSeed = 9217;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
for (let i = 0; i < 48; i++) {
const u = 0.235 + random() * 0.515;
const theta = 0.68 + random() * 0.64;
const point = succulentPoint(u, theta, 0.84);
const normal = new THREE.Vector3(
0,
Math.cos(theta),
Math.sin(theta)
).normalize();
bubbleDummy.position.copy(point).addScaledVector(normal, 0.012);
bubbleDummy.scale.setScalar(0.018 + random() * 0.019);
bubbleDummy.updateMatrix();
bubbles.setMatrixAt(i, bubbleDummy.matrix);
}
bubbles.instanceMatrix.needsUpdate = true;
succulentGroup.add(bubbles);
const succulentStem = tubeFromPoints(
[
new THREE.Vector3(-2.52, -0.10, 0),
new THREE.Vector3(-2.35, -0.07, 0),
new THREE.Vector3(-2.20, -0.02, 0)
],
0.075,
lowerSkinMaterial,
20
);
succulentGroup.add(succulentStem);
/* ---------------- Thin leaf ---------------- */
const thinLength = 4.65;
function thinProfile(u) {
return Math.pow(Math.sin(Math.PI * u), 0.68);
}
function thinWidth(u) {
return 0.77 * thinProfile(u) * (0.90 + 0.16 * u);
}
function thinArch(u) {
return 0.13 * Math.sin(Math.PI * u);
}
function thinTopPoint(u, normalizedWidth) {
const profile = thinProfile(u);
const halfWidth = thinWidth(u);
return new THREE.Vector3(
(u - 0.5) * thinLength,
thinArch(u) + 0.045 * profile + 0.055 * profile * (1 - normalizedWidth * normalizedWidth),
normalizedWidth * halfWidth
);
}
function thinBottomPoint(u, normalizedWidth) {
const profile = thinProfile(u);
const halfWidth = thinWidth(u);
return new THREE.Vector3(
(u - 0.5) * thinLength,
thinArch(u) - 0.045 * profile - 0.025 * profile * (1 - normalizedWidth * normalizedWidth),
normalizedWidth * halfWidth
);
}
function thinInteriorPoint(u, normalizedWidth) {
const profile = thinProfile(u);
const halfWidth = thinWidth(u);
return new THREE.Vector3(
(u - 0.5) * thinLength,
thinArch(u) + 0.006 * profile + 0.030 * profile * (1 - normalizedWidth * normalizedWidth),
normalizedWidth * halfWidth
);
}
const thinGroup = new THREE.Group();
thinGroup.position.set(3.15, -0.16, 0);
thinGroup.rotation.y = 0.035;
scene.add(thinGroup);
const thinHoleU0 = 0.18;
const thinHoleU1 = 0.80;
const thinHoleV0 = -0.55;
const thinHoleV1 = 0.55;
const thinTopGeometry = makeGridSurface({
uSegments: 84,
vSegments: 34,
position: (u, v) => thinTopPoint(u, v * 2 - 1),
skip: (u, v) => {
const width = v * 2 - 1;
return (
u > thinHoleU0 &&
u < thinHoleU1 &&
width > thinHoleV0 &&
width < thinHoleV1
);
},
flip: true
});
const thinTop = new THREE.Mesh(thinTopGeometry, skinMaterial);
thinTop.castShadow = true;
thinTop.receiveShadow = true;
thinGroup.add(thinTop);
const thinBottomGeometry = makeGridSurface({
uSegments: 84,
vSegments: 34,
position: (u, v) => thinBottomPoint(u, v * 2 - 1)
});
const thinBottom = new THREE.Mesh(
thinBottomGeometry,
lowerSkinMaterial
);
thinBottom.castShadow = true;
thinGroup.add(thinBottom);
const thinInteriorGeometry = makeGridSurface({
uSegments: 76,
vSegments: 30,
position: (u, v) => thinInteriorPoint(u, v * 2 - 1),
flip: true
});
const thinInterior = new THREE.Mesh(
thinInteriorGeometry,
mesophyllMaterial
);
thinInterior.castShadow = true;
thinGroup.add(thinInterior);
function addThinRim(a, b) {
const outer = [];
const inner = [];
for (let i = 0; i <= 40; i++) {
const t = i / 40;
const u = a.u + (b.u - a.u) * t;
const width = a.width + (b.width - a.width) * t;
outer.push(thinTopPoint(u, width));
inner.push(thinInteriorPoint(u, width));
}
const rim = new THREE.Mesh(
makeQuadStrip(outer, inner),
cutMaterial
);
rim.castShadow = true;
thinGroup.add(rim);
}
addThinRim(
{ u: thinHoleU0, width: thinHoleV0 },
{ u: thinHoleU0, width: thinHoleV1 }
);
addThinRim(
{ u: thinHoleU1, width: thinHoleV0 },
{ u: thinHoleU1, width: thinHoleV1 }
);
addThinRim(
{ u: thinHoleU0, width: thinHoleV0 },
{ u: thinHoleU1, width: thinHoleV0 }
);
addThinRim(
{ u: thinHoleU0, width: thinHoleV1 },
{ u: thinHoleU1, width: thinHoleV1 }
);
const midveinPoints = [];
for (let i = 0; i <= 44; i++) {
const u = 0.065 + (i / 44) * 0.87;
const point = thinInteriorPoint(u, 0);
point.y += 0.025;
midveinPoints.push(point);
}
thinGroup.add(
tubeFromPoints(midveinPoints, 0.032, vascularMaterial, 72)
);
for (let i = 0; i < 8; i++) {
const u = 0.20 + i * 0.075;
for (const direction of [-1, 1]) {
const points = [];
for (let j = 0; j <= 16; j++) {
const t = j / 16;
const veinU = Math.min(0.93, u + t * 0.105);
const width = direction * t * 0.88;
const point = thinInteriorPoint(veinU, width);
point.y += 0.021;
points.push(point);
}
thinGroup.add(
tubeFromPoints(points, 0.008, vascularMaterial, 24)
);
}
}
for (const width of [-1, 1]) {
const points = [];
for (let i = 0; i <= 40; i++) {
const u = 0.04 + (i / 40) * 0.92;
const point = thinTopPoint(u, width);
point.y -= 0.004;
points.push(point);
}
thinGroup.add(
tubeFromPoints(points, 0.015, skinLightMaterial, 64)
);
}
const mesophyllCellGeometry = new THREE.SphereGeometry(1, 10, 7);
const mesophyllCellMaterial = new THREE.MeshStandardMaterial({
color: 0xb4d09a,
roughness: 0.85,
transparent: true,
opacity: 0.68
});
const mesophyllCells = new THREE.InstancedMesh(
mesophyllCellGeometry,
mesophyllCellMaterial,
40
);
const cellDummy = new THREE.Object3D();
for (let i = 0; i < 40; i++) {
const u = 0.215 + random() * 0.54;
const width = -0.47 + random() * 0.94;
const point = thinInteriorPoint(u, width);
point.y += 0.018;
cellDummy.position.copy(point);
cellDummy.scale.set(0.016, 0.009, 0.026);
cellDummy.rotation.y = random() * Math.PI;
cellDummy.updateMatrix();
mesophyllCells.setMatrixAt(i, cellDummy.matrix);
}
mesophyllCells.instanceMatrix.needsUpdate = true;
thinGroup.add(mesophyllCells);
const thinStem = tubeFromPoints(
[
new THREE.Vector3(-2.54, -0.06, 0),
new THREE.Vector3(-2.38, -0.05, 0),
new THREE.Vector3(-2.22, -0.02, 0)
],
0.045,
lowerSkinMaterial,
20
);
thinGroup.add(thinStem);
/* ---------------- HTML annotations ---------------- */
const annotations = [];
function addAnchor(parent, position) {
const anchor = new THREE.Object3D();
anchor.position.copy(position);
parent.add(anchor);
return anchor;
}
function addAnnotation({
text,
subtext,
className,
anchor,
offsetX,
offsetY
}) {
const label = document.createElement("div");
label.className = `callout ${className}`;
label.innerHTML = `${text}<small>${subtext}</small>`;
document.querySelector(".interface").appendChild(label);
const line = document.createElementNS(
"http://www.w3.org/2000/svg",
"line"
);
const dot = document.createElementNS(
"http://www.w3.org/2000/svg",
"circle"
);
dot.setAttribute("r", "3.5");
leaders.append(line, dot);
annotations.push({
label,
line,
dot,
anchor,
offsetX,
offsetY
});
}
addAnnotation({
text: "Protective skin",
subtext: "Epidermis + cuticle",
className: "skin",
anchor: addAnchor(
succulentGroup,
succulentPoint(0.88, 0.34)
),
offsetX: -72,
offsetY: -74
});
addAnnotation({
text: "Water-storing tissue",
subtext: "Broad parenchyma",
className: "storage",
anchor: addAnchor(
succulentGroup,
succulentPoint(0.50, 1.05, 0.84)
),
offsetX: -84,
offsetY: 78
});
addAnnotation({
text: "Thin skin",
subtext: "Epidermis",
className: "skin",
anchor: addAnchor(
thinGroup,
thinTopPoint(0.88, -0.66)
),
offsetX: 70,
offsetY: -70
});
addAnnotation({
text: "Exchange tissue",
subtext: "Compact mesophyll",
className: "mesophyll",
anchor: addAnchor(
thinGroup,
thinInteriorPoint(0.49, 0.34)
),
offsetX: 85,
offsetY: 76
});
const projected = new THREE.Vector3();
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
annotation.anchor.getWorldPosition(projected);
projected.project(camera);
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelX = anchorX + annotation.offsetX;
const labelY = anchorY + annotation.offsetY;
annotation.label.style.left = `${labelX}px`;
annotation.label.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);
}
}
/* ---------------- Custom camera controls ---------------- */
const target = new THREE.Vector3(0, -0.05, 0);
const spherical = new THREE.Spherical(12.8, 1.08, 0);
let autoRotate = true;
let dragging = false;
let previousX = 0;
let previousY = 0;
const pointers = new Map();
let pinchDistance = 0;
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
if (reducedMotion) {
autoRotate = false;
rotateButton.classList.remove("active");
}
function fitFactor() {
const aspect = window.innerWidth / window.innerHeight;
return Math.max(1, 1.42 / aspect);
}
spherical.radius *= fitFactor();
function updateCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
canvas.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
}
if (pointers.size === 2) {
const points = [...pointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
spherical.radius *= pinchDistance / distance;
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
8,
29
);
}
pinchDistance = distance;
return;
}
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi + deltaY * 0.005,
0.48,
1.43
);
previousX = event.clientX;
previousY = event.clientY;
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 0) {
dragging = false;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius,
8,
29
);
},
{ passive: false }
);
rotateButton.addEventListener("click", () => {
autoRotate = !autoRotate;
rotateButton.classList.toggle("active", autoRotate);
});
labelsButton.addEventListener("click", () => {
const hidden = document.body.classList.toggle(
"annotations-hidden"
);
labelsButton.classList.toggle("active", !hidden);
});
labelsButton.classList.add("active");
resetButton.addEventListener("click", () => {
spherical.radius = 12.8 * fitFactor();
spherical.phi = 1.08;
spherical.theta = 0;
target.set(0, -0.05, 0);
updateCamera();
});
/* ---------------- Resize and animation ---------------- */
let previousAspect = window.innerWidth / window.innerHeight;
window.addEventListener("resize", () => {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const oldFit = Math.max(1, 1.42 / previousAspect);
const newFit = Math.max(1, 1.42 / aspect);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * (newFit / oldFit),
8,
29
);
previousAspect = aspect;
camera.aspect = aspect;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
leaders.setAttribute("viewBox", `0 0 ${width} ${height}`);
});
leaders.setAttribute(
"viewBox",
`0 0 ${window.innerWidth} ${window.innerHeight}`
);
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
if (autoRotate && !dragging && pointers.size === 0) {
spherical.theta += delta * 0.065;
}
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
loading.classList.add("done");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```