Prompt specification
Build or customize the Three.js 3D scene "Lichen layered partner diagram" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Lichen layered partner diagram
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/lichen-layered-partner-diagram-x0745
Scene Description Prompt:
Please make a voxel Three.js scene in one standalone HTML file using cdnjs. Show a magnified lichen section with fungal structure and photosynthetic partner cells, plus a rock-scale reference; labels should identify the simplified selected association clearly.
Working Three.js Starter (lichen-layered-partner-diagram-x0745):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lichen: A Partnership Magnified</title>
<style>
:root {
--ink: #eef8f4;
--muted: #a8beb9;
--panel: rgba(9, 24, 28, 0.78);
--line: rgba(190, 225, 216, 0.16);
--cyan: #79e6dc;
--green: #62d887;
--gold: #e1a04c;
--rock: #bdc8c5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071519;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
touch-action: none;
cursor: grab;
}
#app canvas.grabbing {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 44%, transparent 30%, rgba(1, 8, 11, 0.32) 100%),
linear-gradient(180deg, rgba(4, 13, 16, 0.14), rgba(4, 13, 16, 0.32));
}
header {
position: fixed;
top: 28px;
left: 30px;
width: min(390px, calc(100vw - 60px));
pointer-events: none;
z-index: 5;
}
.eyebrow {
margin-bottom: 9px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 360px;
font-size: clamp(30px, 4.2vw, 56px);
line-height: 0.98;
letter-spacing: -0.055em;
font-weight: 780;
text-wrap: balance;
}
header p {
max-width: 350px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.key {
position: fixed;
top: 28px;
right: 28px;
z-index: 6;
width: 285px;
padding: 17px 18px 16px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.22);
}
.key-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: #d9e9e5;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.selected-pill {
padding: 4px 7px;
border: 1px solid rgba(121, 230, 220, 0.25);
border-radius: 999px;
color: var(--cyan);
background: rgba(121, 230, 220, 0.08);
font-size: 9px;
letter-spacing: 0.12em;
}
.key-row {
display: grid;
grid-template-columns: 11px 1fr;
gap: 10px;
align-items: start;
margin-top: 12px;
}
.swatch {
width: 9px;
height: 9px;
margin-top: 4px;
border-radius: 2px;
box-shadow: 0 0 13px currentColor;
}
.swatch.gold {
color: var(--gold);
background: var(--gold);
}
.swatch.green {
color: var(--green);
background: var(--green);
}
.key-row strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
font-weight: 720;
}
.key-row span {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.4;
}
.key-note {
margin-top: 15px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #829b96;
font-size: 10px;
line-height: 1.5;
}
.view-tag {
position: fixed;
top: 28px;
left: 50%;
z-index: 4;
display: flex;
align-items: center;
gap: 10px;
transform: translateX(-50%);
color: #dcece7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
pointer-events: none;
}
.view-tag .number {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border: 1px solid rgba(225, 160, 76, 0.45);
border-radius: 50%;
color: var(--gold);
font-size: 9px;
}
.view-tag small {
display: block;
margin-top: 3px;
color: #718a85;
font-size: 8px;
letter-spacing: 0.12em;
}
.scale-card {
position: fixed;
right: 28px;
bottom: 26px;
z-index: 5;
width: 285px;
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(14px);
pointer-events: none;
}
.scale-card .label {
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.scale-card strong {
display: block;
margin: 7px 0 5px;
font-size: 18px;
font-weight: 750;
letter-spacing: -0.02em;
}
.scale-card p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.help {
position: fixed;
left: 30px;
bottom: 26px;
z-index: 5;
display: flex;
align-items: center;
gap: 10px;
color: #819792;
font-size: 10px;
pointer-events: none;
}
.mouse-icon {
position: relative;
width: 18px;
height: 25px;
border: 1px solid #6d8882;
border-radius: 10px;
}
.mouse-icon::after {
content: "";
position: absolute;
top: 4px;
left: 7px;
width: 2px;
height: 6px;
border-radius: 2px;
background: var(--cyan);
}
#reset {
position: fixed;
right: 28px;
top: 222px;
z-index: 7;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 8px;
color: #bcd1cb;
background: rgba(9, 24, 28, 0.74);
font: inherit;
font-size: 10px;
cursor: pointer;
}
#reset:hover {
color: var(--ink);
border-color: rgba(121, 230, 220, 0.45);
}
#leaders,
#labels {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 3;
}
#leaders {
overflow: visible;
}
.leader {
stroke: rgba(197, 225, 218, 0.52);
stroke-width: 1;
stroke-dasharray: 2 4;
}
.leader.gold {
stroke: rgba(225, 160, 76, 0.72);
}
.leader.green {
stroke: rgba(98, 216, 135, 0.75);
}
.leader.cyan {
stroke: rgba(121, 230, 220, 0.75);
}
.anchor-dot {
fill: #dcece7;
stroke: rgba(8, 19, 23, 0.9);
stroke-width: 2;
}
.annotation {
position: absolute;
width: 190px;
padding: 9px 11px 10px;
border: 1px solid rgba(191, 222, 214, 0.18);
border-left: 2px solid #a9bdb7;
border-radius: 8px;
color: var(--ink);
background: rgba(6, 19, 23, 0.82);
box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(8px);
opacity: 0;
transition: opacity 180ms ease;
}
.annotation.visible {
opacity: 1;
}
.annotation.gold {
border-left-color: var(--gold);
}
.annotation.green {
border-left-color: var(--green);
}
.annotation.cyan {
border-left-color: var(--cyan);
}
.annotation .annotation-title {
display: block;
margin-bottom: 4px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.015em;
}
.annotation .annotation-sub {
display: block;
color: #98ada8;
font-size: 9px;
line-height: 1.4;
}
@media (max-width: 900px) {
header {
top: 20px;
left: 20px;
}
header p {
display: none;
}
.key {
top: 20px;
right: 20px;
width: 245px;
}
.view-tag {
display: none;
}
#reset {
right: 20px;
top: 210px;
}
.scale-card {
right: 20px;
bottom: 20px;
width: 245px;
}
.help {
left: 20px;
bottom: 20px;
}
}
@media (max-width: 620px) {
h1 {
font-size: 30px;
}
.key {
top: auto;
right: 12px;
bottom: 12px;
width: 218px;
padding: 12px;
}
.key-note,
.scale-card,
.help {
display: none;
}
#reset {
top: 112px;
right: 12px;
}
.annotation {
width: 150px;
padding: 7px 9px;
}
.annotation .annotation-title {
font-size: 9px;
}
.annotation .annotation-sub {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="vignette"></div>
<header>
<div class="eyebrow">Field study · lichen symbiosis</div>
<h1>A partnership, magnified</h1>
<p>
A simplified green-algal lichen section, paired with its mineral
substrate at rock scale.
</p>
</header>
<aside class="key">
<div class="key-heading">
Selected association
<span class="selected-pill">simplified model</span>
</div>
<div class="key-row">
<i class="swatch gold"></i>
<div>
<strong>Fungal partner</strong>
<span>Ascomycete fungus forming a branching hyphal network.</span>
</div>
</div>
<div class="key-row">
<i class="swatch green"></i>
<div>
<strong>Photosynthetic partner</strong>
<span>Green algal cells supplying photosynthetic products.</span>
</div>
</div>
<div class="key-note">
This model shows one common green-algal association. Cell shapes,
spacing, and the enlargement are schematic rather than anatomically
exact.
</div>
</aside>
<div class="view-tag">
<span class="number">01</span>
<div>
Magnified section
<small>cellular view · not to scale</small>
</div>
</div>
<button id="reset" type="button">Reset view</button>
<div class="scale-card">
<div class="label">Rock-scale reference</div>
<strong>1 cm substrate bar</strong>
<p>
Rock edge ≈ 4 cm · selected lichen patch ≈ 8 mm.
The cellular panel is a schematic enlargement.
</p>
</div>
<div class="help">
<span class="mouse-icon"></span>
<span>Drag to orbit · scroll to zoom · double-click to reset</span>
</div>
<svg id="leaders" aria-hidden="true"></svg>
<div id="labels" aria-hidden="true"></div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const app = document.querySelector("#app");
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 voxel illustration of a lichen section and its rock substrate"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071519);
scene.fog = new THREE.Fog(0x071519, 16, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const controlsTarget = new THREE.Vector3(0, 1.05, 0);
const spherical = new THREE.Spherical(13.8, 1.08, 0.12);
const cameraOffset = new THREE.Vector3();
function applyCamera() {
cameraOffset.setFromSpherical(spherical);
camera.position.copy(controlsTarget).add(cameraOffset);
camera.lookAt(controlsTarget);
}
applyCamera();
scene.add(new THREE.HemisphereLight(0xc8e5e7, 0x142225, 2.15));
const keyLight = new THREE.DirectionalLight(0xffe4bd, 3.25);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x70d8e2, 1.55);
fillLight.position.set(7, 5, -6);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0x92f1c5, 1.15);
rimLight.position.set(-7, 3, -5);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 22),
new THREE.MeshStandardMaterial({
color: 0x0b1b20,
roughness: 0.95,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.9;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 48, 0x2f6666, 0x18383b);
grid.position.y = -0.89;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// -------------------------------------------------------------------------
// Voxel helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color, options = {}) {
const key = String(color) + JSON.stringify(options);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.03,
...options
})
);
}
return materialCache.get(key);
}
function cube(
parent,
color,
x,
y,
z,
sx,
sy = sx,
sz = sx,
options = {}
) {
const mesh = new THREE.Mesh(
unitBox,
typeof color === "object" ? color : getMaterial(color, options)
);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let randomSeed = 48271;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
// -------------------------------------------------------------------------
// Magnified lichen section: a voxelized cutaway
// -------------------------------------------------------------------------
const section = new THREE.Group();
section.position.set(-3.1, 1.25, 0);
scene.add(section);
const matrixPalette = [
0x493b2c,
0x584735,
0x403a2d,
0x65503a,
0x3b3c31,
0x514333
];
// Two shallow layers form the cut fungal tissue.
for (let layer = 0; layer < 2; layer++) {
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 12; col++) {
const x = (col - 5.5) * 0.5;
const y = (row - 3.5) * 0.5;
const z = layer === 0 ? -0.28 : -0.51;
// Sparse gaps in the rear layer suggest internal spaces.
if (
layer === 1 &&
((col * 5 + row * 7 + layer * 3) % 11 === 0)
) {
continue;
}
const color =
matrixPalette[
(col + row * 2 + layer * 3) % matrixPalette.length
];
cube(
section,
color,
x,
y,
z,
0.47,
0.47,
layer === 0 ? 0.18 : 0.17
);
}
}
}
// Branches are chains of small cubes to preserve the voxel language.
const hyphaPaths = [
{
points: [
[-2.75, -1.2], [-2.05, -0.55], [-1.25, -0.85],
[-0.45, -0.05], [0.35, -0.3], [1.15, 0.5],
[2.05, 0.2], [2.72, 0.82]
],
width: 0.18
},
{
points: [
[-2.05, -0.55], [-2.3, 0.35], [-1.95, 0.95],
[-2.35, 1.48]
],
width: 0.13
},
{
points: [
[-1.25, -0.85], [-1.05, -1.38], [-0.5, -1.56],
[0.05, -1.25]
],
width: 0.13
},
{
points: [
[-0.45, -0.05], [-0.7, 0.58], [-0.25, 1.2],
[0.38, 1.5]
],
width: 0.16
},
{
points: [
[0.35, -0.3], [0.65, -0.9], [1.42, -1.02],
[1.85, -0.55]
],
width: 0.13
},
{
points: [
[1.15, 0.5], [1.35, 1.08], [1.93, 1.45],
[2.48, 1.28]
],
width: 0.15
},
{
points: [
[-1.95, 0.95], [-1.2, 1.12], [-0.65, 1.6],
[-0.02, 1.72]
],
width: 0.12
},
{
points: [
[0.38, 1.5], [0.6, 1.83], [1.15, 1.83]
],
width: 0.12
}
];
const hyphaColors = [0xd69443, 0xb96c31, 0xe0aa58, 0x9d5528];
function addHypha(points, width, pathIndex) {
for (let segment = 0; segment < points.length - 1; segment++) {
const a = points[segment];
const b = points[segment + 1];
const dx = b[0] - a[0];
const dy = b[1] - a[1];
const length = Math.hypot(dx, dy);
const steps = Math.max(2, Math.ceil(length / 0.115));
for (let step = 0; step <= steps; step++) {
const t = step / steps;
const x = a[0] + dx * t;
const y = a[1] + dy * t;
const z = -0.035 + Math.sin(step * 1.37 + pathIndex) * 0.045;
const size = width * (step % 7 === 0 ? 1.22 : 1);
cube(
section,
hyphaColors[(step + pathIndex) % hyphaColors.length],
x,
y,
z,
size,
size,
size
);
}
}
}
hyphaPaths.forEach((path, index) => {
addHypha(path.points, path.width, index);
});
// Bright, block-built photosynthetic partner cells.
const algalPositions = [
[-1.95, 0.3, 0.94],
[-0.85, 0.62, 1.02],
[0.15, -0.7, 0.9],
[1.45, -0.25, 0.96],
[2.1, 1.15, 0.88],
[-1.45, 1.35, 0.91],
[-0.25, 1.2, 1.08],
[-2.25, -1.2, 0.86],
[0.75, 0.85, 0.93],
[-0.55, -1.25, 0.9]
];
function addAlgalCell(x, y, scale = 1) {
const cell = new THREE.Group();
cell.position.set(x, y, 0.08);
cell.scale.setScalar(scale);
section.add(cell);
cube(cell, 0x36a961, 0, 0, 0, 0.42, 0.42, 0.34);
cube(cell, 0x49c876, -0.22, -0.22, 0.015, 0.17, 0.17, 0.22);
cube(cell, 0x49c876, 0.22, -0.22, 0.015, 0.17, 0.17, 0.22);
cube(cell, 0x49c876, -0.22, 0.22, 0.015, 0.17, 0.17, 0.22);
cube(cell, 0x49c876, 0.22, 0.22, 0.015, 0.17, 0.17, 0.22);
// Small internal chloroplast-like block.
cube(
cell,
0xa5ed72,
0.025,
-0.015,
0.215,
0.15,
0.22,
0.09,
{
emissive: 0x2f8c36,
emissiveIntensity: 0.22
}
);
}
algalPositions.forEach(([x, y, scale]) => {
addAlgalCell(x, y, scale);
});
// Thin bracket-like corner framing the cutaway.
const frameColor = 0xc9dcd6;
const frameParts = [
[-3.04, -1.94, 0.09, 0.32, 0.045, 0.045],
[-3.04, -1.78, 0.09, 0.045, 0.32, 0.045],
[3.04, -1.94, 0.09, 0.32, 0.045, 0.045],
[2.88, -1.78, 0.09, 0.045, 0.32, 0.045],
[-3.04, 1.94, 0.09, 0.32, 0.045, 0.045],
[-3.04, 1.78, 0.09, 0.045, 0.32, 0.045],
[3.04, 1.94, 0.09, 0.32, 0.045, 0.045],
[2.88, 1.78, 0.09, 0.045, 0.32, 0.045]
];
frameParts.forEach((p) => cube(section, frameColor, ...p));
// -------------------------------------------------------------------------
// Rock-scale reference and selected lichen patch
// -------------------------------------------------------------------------
const rock = new THREE.Group();
rock.position.set(3.45, 0.65, 0.35);
scene.add(rock);
const rockPalette = [
0x65706d,
0x727c78,
0x596460,
0x7e8580,
0x505c59,
0x89908a
];
for (let iz = 0; iz < 4; iz++) {
for (let iy = 0; iy < 6; iy++) {
for (let ix = 0; ix < 8; ix++) {
const jitterX = (random() - 0.5) * 0.055;
const jitterY = (random() - 0.5) * 0.055;
const x = (ix - 3.5) * 0.5 + jitterX;
const y = (iy - 2.5) * 0.5 + jitterY;
const z = (iz - 1.5) * 0.5;
const color =
rockPalette[Math.floor(random() * rockPalette.length)];
cube(rock, color, x, y, z, 0.47, 0.47, 0.47);
}
}
}
// A visible mixed-color lichen thallus patch on the rock face.
const patchCenterX = 0.3;
const patchCenterY = 0.55;
for (let py = 0; py < 4; py++) {
for (let px = 0; px < 6; px++) {
const isGreen = (px * 3 + py * 5) % 7 < 3;
const color = isGreen ? 0x5c9f63 : 0xa67943;
cube(
rock,
color,
patchCenterX + (px - 2.5) * 0.14,
patchCenterY + (py - 1.5) * 0.14,
1.025,
0.135,
0.135,
0.085,
{
roughness: 0.92
}
);
}
}
// Cyan corner brackets identify the small sampled patch.
const selectionMaterial = new THREE.MeshBasicMaterial({
color: 0x79e6dc,
transparent: true,
opacity: 0.9
});
const selectionBrackets = [];
const sx0 = patchCenterX - 0.48;
const sx1 = patchCenterX + 0.48;
const sy0 = patchCenterY - 0.34;
const sy1 = patchCenterY + 0.34;
function selectionBar(x, y, width, height) {
const mesh = cube(
rock,
selectionMaterial,
x,
y,
1.105,
width,
height,
0.035
);
mesh.castShadow = false;
mesh.receiveShadow = false;
selectionBrackets.push(mesh);
}
selectionBar(sx0 + 0.1, sy0, 0.2, 0.035);
selectionBar(sx0, sy0 + 0.1, 0.035, 0.2);
selectionBar(sx1 - 0.1, sy0, 0.2, 0.035);
selectionBar(sx1, sy0 + 0.1, 0.035, 0.2);
selectionBar(sx0 + 0.1, sy1, 0.2, 0.035);
selectionBar(sx0, sy1 - 0.1, 0.035, 0.2);
selectionBar(sx1 - 0.1, sy1, 0.2, 0.035);
selectionBar(sx1, sy1 - 0.1, 0.035, 0.2);
// A physical 1 cm bar: the entire 4-unit rock edge represents 4 cm.
for (let i = 0; i < 10; i++) {
cube(
rock,
i % 2 === 0 ? 0xe5eee9 : 0x263d40,
-0.475 + i * 0.1,
-1.18,
1.1,
0.1,
0.09,
0.08
);
}
cube(rock, 0xe5eee9, -0.525, -1.18, 1.1, 0.035, 0.16, 0.08);
cube(rock, 0xe5eee9, 0.525, -1.18, 1.1, 0.035, 0.16, 0.08);
// A dashed visual link from the selected patch to the enlarged section.
const zoomLineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(3.75, 1.2, 1.46),
new THREE.Vector3(2.7, 1.08, 1.05),
new THREE.Vector3(1.3, 1.05, 0.62),
new THREE.Vector3(0.05, 1.25, 0.08)
]);
const zoomLine = new THREE.Line(
zoomLineGeometry,
new THREE.LineDashedMaterial({
color: 0x79e6dc,
transparent: true,
opacity: 0.42,
dashSize: 0.11,
gapSize: 0.09,
depthWrite: false
})
);
zoomLine.computeLineDistances();
scene.add(zoomLine);
// -------------------------------------------------------------------------
// Projected HTML labels and leader lines
// -------------------------------------------------------------------------
const labelLayer = document.querySelector("#labels");
const leaderLayer = document.querySelector("#leaders");
const svgNS = "http://www.w3.org/2000/svg";
const annotationDefinitions = [
{
id: "fungus",
tone: "gold",
title: "Fungal partner",
subtitle: "Branching hyphae forming the mycelial structure",
anchor: new THREE.Vector3(-3.55, 1.2, 0.12),
offset: [82, 24]
},
{
id: "algae",
tone: "green",
title: "Photosynthetic partner cells",
subtitle: "Green-algal cells distributed among the hyphae",
anchor: new THREE.Vector3(-3.35, 2.45, 0.32),
offset: [86, -88]
},
{
id: "patch",
tone: "cyan",
title: "Selected lichen patch",
subtitle: "≈ 8 mm area sampled from the rock face",
anchor: new THREE.Vector3(3.75, 1.2, 1.5),
offset: [82, -68]
},
{
id: "rock",
tone: "rock",
title: "Mineral substrate",
subtitle: "Voxelized rock face, shown for spatial context",
anchor: new THREE.Vector3(4.95, 1.28, 0.95),
offset: [72, 20]
},
{
id: "scale",
tone: "scale",
title: "1 cm reference",
subtitle: "Rock-scale bar shown on the substrate",
anchor: new THREE.Vector3(3.45, -0.53, 1.55),
offset: [68, 4]
}
];
const annotations = annotationDefinitions.map((definition) => {
const element = document.createElement("div");
element.className = `annotation ${definition.tone}`;
element.innerHTML = `
<span class="annotation-title">${definition.title}</span>
<span class="annotation-sub">${definition.subtitle}</span>
`;
labelLayer.appendChild(element);
const line = document.createElementNS(svgNS, "line");
line.setAttribute("class", `leader ${definition.tone}`);
leaderLayer.appendChild(line);
const dot = document.createElementNS(svgNS, "circle");
dot.setAttribute("class", "anchor-dot");
dot.setAttribute("r", "3.5");
leaderLayer.appendChild(dot);
return { ...definition, element, line, dot };
});
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
annotations.forEach((annotation) => {
const projected = annotation.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.classList.toggle("visible", visible);
annotation.line.style.display = visible ? "" : "none";
annotation.dot.style.display = visible ? "" : "none";
if (!visible) return;
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const labelWidth = annotation.element.offsetWidth;
const labelHeight = annotation.element.offsetHeight;
const desiredX = anchorX + annotation.offset[0];
const desiredY = anchorY + annotation.offset[1];
const x = THREE.MathUtils.clamp(
desiredX,
10,
Math.max(10, width - labelWidth - 10)
);
const y = THREE.MathUtils.clamp(
desiredY,
10,
Math.max(10, height - labelHeight - 10)
);
annotation.element.style.left = `${x}px`;
annotation.element.style.top = `${y}px`;
const attachLeft = annotation.offset[0] < 0;
const endX = attachLeft ? x : x + labelWidth;
const endY = y + labelHeight * 0.5;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", endX);
annotation.line.setAttribute("y2", endY);
annotation.dot.setAttribute("cx", anchorX);
annotation.dot.setAttribute("cy", anchorY);
});
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, reset
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("grabbing");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.005,
0.42,
1.43
);
applyCamera();
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("grabbing");
if (event?.pointerId !== undefined) {
try {
renderer.domElement.releasePointerCapture(event.pointerId);
} catch (_) {
// Pointer may already have been released.
}
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const zoomFactor = Math.exp(event.deltaY * 0.001);
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * zoomFactor,
8.2,
23
);
applyCamera();
},
{ passive: false }
);
function resetView() {
spherical.set(13.8, 1.08, 0.12);
controlsTarget.set(0, 1.05, 0);
applyCamera();
}
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.12;
if (event.key === "ArrowLeft") spherical.theta += step;
if (event.key === "ArrowRight") spherical.theta -= step;
if (event.key === "ArrowUp") {
spherical.phi = Math.max(0.42, spherical.phi - step);
}
if (event.key === "ArrowDown") {
spherical.phi = Math.min(1.43, spherical.phi + step);
}
if (event.key.toLowerCase() === "r") resetView();
applyCamera();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = aspect;
camera.fov = aspect < 0.8 ? 54 : 38;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const pulse = 0.64 + Math.sin(clock.getElapsedTime() * 2.2) * 0.22;
selectionMaterial.opacity = pulse;
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```