Prompt specification
Build or customize the Three.js 3D scene "Museum of fictional organism relationships" 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: Museum of fictional organism relationships
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/museum-of-fictional-organism-relationships-x0947
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows phylogenetic trees. Compose specimens around a central branching tree with selected shared features; distinguish ancestral nodes from living tips and avoid treating one living species as another's direct ancestor. Voxel style.
Working Three.js Starter (museum-of-fictional-organism-relationships-x0947):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Phylogeny — Comparative Tree Lab</title>
<style>
:root {
--ink: #20302d;
--muted: #6e7872;
--paper: #f4f0e5;
--panel: rgba(255, 253, 247, 0.88);
--line: rgba(32, 48, 45, 0.13);
--teal: #238b7d;
--amber: #d8953f;
--living: #19a98d;
--shadow: 0 18px 45px rgba(39, 52, 47, 0.13);
}
* { 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;
}
body::after {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
z-index: 3;
background: radial-gradient(circle at 50% 45%, transparent 45%, rgba(67, 65, 54, 0.09));
}
button {
font: inherit;
color: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#view {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#view.grabbing { cursor: grabbing; }
#view.pickable { cursor: pointer; }
#labels {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.labels-off { opacity: 0; }
.node-label,
.tip-label {
position: absolute;
left: 0;
top: 0;
white-space: nowrap;
will-change: transform;
}
.node-label {
color: #9a682c;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
padding: 3px 6px;
border-left: 2px solid rgba(216, 149, 63, 0.65);
background: rgba(250, 246, 235, 0.7);
text-shadow: 0 1px 0 white;
}
.node-label.dim,
.tip-label.dim {
opacity: 0.18;
}
.tip-label {
pointer-events: auto;
cursor: pointer;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 7px;
border: 1px solid rgba(32, 48, 45, 0.12);
border-radius: 4px;
background: rgba(255, 253, 247, 0.86);
box-shadow: 0 5px 16px rgba(38, 49, 45, 0.09);
transition: opacity 160ms ease, transform 160ms ease, border-color 160ms ease;
}
.tip-label:hover,
.tip-label.selected {
border-color: rgba(35, 139, 125, 0.65);
background: rgba(255, 255, 250, 0.98);
}
.tip-label .dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--living);
box-shadow: 0 0 0 3px rgba(25, 169, 141, 0.12);
}
.tip-label strong {
display: block;
font-size: 11px;
line-height: 1.05;
letter-spacing: 0.01em;
}
.tip-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.11em;
}
header {
position: fixed;
z-index: 6;
top: 0;
left: 0;
right: 0;
height: 82px;
padding: 17px 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
background: linear-gradient(180deg, rgba(244, 240, 229, 0.98), rgba(244, 240, 229, 0.73));
border-bottom: 1px solid var(--line);
backdrop-filter: blur(12px);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 240px;
}
.brand-mark {
width: 37px;
height: 37px;
position: relative;
flex: 0 0 auto;
}
.brand-mark i {
position: absolute;
display: block;
width: 13px;
height: 13px;
background: var(--teal);
box-shadow: inset -3px -3px rgba(0,0,0,0.08);
}
.brand-mark i:nth-child(1) { left: 0; top: 12px; }
.brand-mark i:nth-child(2) { left: 12px; top: 0; background: #5aaa9b; }
.brand-mark i:nth-child(3) { right: 0; top: 12px; background: var(--amber); }
.brand-mark i:nth-child(4) { left: 12px; bottom: 0; background: #38645c; }
.brand h1 {
margin: 0;
font-size: 15px;
line-height: 1.1;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
}
.header-center {
text-align: center;
}
.header-center strong {
display: block;
font-size: 12px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.header-center span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
}
.header-badge {
min-width: 240px;
display: flex;
justify-content: flex-end;
}
.badge {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(255,255,255,0.48);
color: #4e5e58;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--living);
box-shadow: 0 0 0 4px rgba(25, 169, 141, 0.12);
}
.panel {
position: fixed;
z-index: 5;
top: 104px;
border: 1px solid var(--line);
border-radius: 6px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
}
.info-panel {
left: 24px;
width: 315px;
padding: 19px;
}
.trait-panel {
right: 24px;
width: 286px;
padding: 18px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.info-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
#selection-title {
margin: 0;
font-size: 23px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.status-pill {
flex: 0 0 auto;
padding: 5px 7px;
border-radius: 2px;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.status-pill.living {
color: #08705f;
background: rgba(25, 169, 141, 0.13);
}
.status-pill.ancestor {
color: #986323;
background: rgba(216, 149, 63, 0.16);
}
#selection-description {
margin: 13px 0 15px;
color: #5f6964;
font-size: 12px;
line-height: 1.55;
}
.facts {
display: grid;
gap: 7px;
margin-bottom: 15px;
}
.fact {
display: flex;
align-items: flex-start;
gap: 8px;
color: #53615c;
font-size: 10px;
line-height: 1.35;
}
.fact::before {
content: "";
width: 5px;
height: 5px;
margin-top: 4px;
flex: 0 0 auto;
background: #7a8d85;
}
.trait-list {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin: 0 0 15px;
}
.trait-tag {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 5px 7px;
border: 1px solid rgba(32,48,45,0.1);
border-radius: 2px;
background: rgba(255,255,255,0.52);
font-size: 9px;
font-weight: 700;
color: #52605a;
}
.trait-tag i {
width: 6px;
height: 6px;
border-radius: 1px;
background: var(--trait-color, #82938d);
}
.section-rule {
height: 1px;
margin: 14px 0;
background: var(--line);
}
.index-title {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
margin-bottom: 8px;
}
#taxon-index {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 5px;
}
.index-button {
border: 1px solid rgba(32,48,45,0.1);
background: rgba(255,255,255,0.45);
padding: 7px 8px;
border-radius: 2px;
cursor: pointer;
text-align: left;
font-size: 10px;
transition: background 140ms ease, border-color 140ms ease;
}
.index-button:hover,
.index-button.active {
background: rgba(25, 169, 141, 0.09);
border-color: rgba(25, 169, 141, 0.38);
}
.index-button span {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 6px;
border-radius: 1px;
vertical-align: 1px;
}
.caution {
margin: 13px 0 0;
padding: 10px 11px;
border-left: 2px solid var(--amber);
background: rgba(216,149,63,0.08);
color: #786349;
font-size: 9px;
line-height: 1.45;
}
.trait-panel h2 {
margin: 0;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.trait-panel > p {
margin: 8px 0 13px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
#feature-buttons {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.feature-button {
cursor: pointer;
border: 1px solid rgba(32,48,45,0.12);
border-radius: 3px;
padding: 7px 8px;
background: rgba(255,255,255,0.5);
font-size: 9px;
font-weight: 750;
transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
.feature-button:hover { transform: translateY(-1px); }
.feature-button.active {
color: white;
border-color: transparent;
background: var(--feature-color, var(--teal));
}
#feature-stat {
margin: 13px 0;
padding: 10px;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(255,255,255,0.45);
color: #596760;
font-size: 10px;
line-height: 1.4;
}
.toggle-row {
display: flex;
gap: 6px;
margin-top: 12px;
}
.small-button {
flex: 1;
cursor: pointer;
border: 1px solid var(--line);
border-radius: 3px;
background: rgba(255,255,255,0.58);
padding: 8px 6px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.04em;
}
.small-button:hover {
background: white;
border-color: rgba(32,48,45,0.28);
}
.legend {
position: fixed;
z-index: 5;
left: 24px;
bottom: 22px;
display: flex;
gap: 15px;
align-items: center;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 4px;
background: rgba(255,253,247,0.77);
backdrop-filter: blur(10px);
color: #5c6963;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.03em;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.legend-shape {
width: 12px;
height: 12px;
border-radius: 2px;
background: var(--amber);
box-shadow: 4px 4px 0 -2px rgba(216,149,63,0.35);
}
.legend-shape.living {
background: var(--living);
box-shadow: 4px 4px 0 -2px rgba(25,169,141,0.35);
}
.legend-shape.branch {
width: 18px;
height: 5px;
border-radius: 1px;
background: #466d64;
box-shadow: none;
}
.hint {
position: fixed;
z-index: 5;
right: 24px;
bottom: 24px;
color: rgba(57,72,66,0.66);
font-size: 9px;
letter-spacing: 0.04em;
pointer-events: none;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: var(--paper);
color: #5e6b65;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden { opacity: 0; pointer-events: none; }
@media (max-width: 900px) {
header { height: 68px; padding: 12px 14px; }
.header-center { display: none; }
.brand, .header-badge { min-width: 0; }
.brand p { display: none; }
.brand h1 { font-size: 12px; }
.header-badge .badge { font-size: 8px; padding: 7px 8px; }
.info-panel {
top: auto;
left: 12px;
bottom: 12px;
width: min(315px, calc(100vw - 24px));
max-height: 42vh;
overflow: auto;
padding: 14px;
}
.trait-panel {
top: 80px;
right: 12px;
width: 235px;
padding: 13px;
}
.legend { display: none; }
.hint { left: 12px; right: auto; bottom: 5px; font-size: 8px; }
#selection-title { font-size: 18px; }
#selection-description { font-size: 10px; }
.index-title, #taxon-index { display: none; }
.node-label { display: none; }
}
@media (max-width: 560px) {
.trait-panel {
left: 12px;
right: 12px;
top: 80px;
width: auto;
}
.trait-panel > p, .caution, #feature-stat { display: none; }
#feature-buttons { margin-top: 9px; }
.feature-button { padding: 6px 7px; font-size: 8px; }
.info-panel { max-height: 38vh; }
.tip-label { padding: 4px 6px; }
.tip-label small { display: none; }
}
</style>
</head>
<body>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<h1>Voxel Phylogeny</h1>
<p>Comparative anatomy / branching relationships</p>
</div>
</div>
<div class="header-center">
<strong>Common descent, reconstructed</strong>
<span>Seven living lineages · seven inferred ancestral nodes</span>
</div>
<div class="header-badge">
<span class="badge">Cladogram · 7 living tips</span>
</div>
</header>
<div id="stage">
<canvas id="view" aria-label="Interactive three-dimensional voxel phylogenetic tree"></canvas>
<div id="labels"></div>
</div>
<aside class="panel info-panel" aria-live="polite">
<p class="eyebrow">Selected branch</p>
<div class="info-heading">
<h2 id="selection-title">Red fox</h2>
<span id="selection-status" class="status-pill living">Living tip</span>
</div>
<p id="selection-description"></p>
<div id="selection-facts" class="facts"></div>
<div id="selection-traits" class="trait-list"></div>
<div class="section-rule"></div>
<div class="index-title">
<span>Exhibit index</span>
<span>Select a specimen</span>
</div>
<div id="taxon-index"></div>
<p class="caution">
This is a branching hypothesis, not an evolutionary “ladder.” A living species is not shown as the direct ancestor of another living species.
</p>
</aside>
<aside class="panel trait-panel">
<p class="eyebrow">Comparative overlay</p>
<h2>Shared features</h2>
<p>Highlight lineages possessing a feature and the branches leading to them.</p>
<div id="feature-buttons">
<button class="feature-button active" data-feature="all" style="--feature-color:#238b7d">All lineages</button>
<button class="feature-button" data-feature="jaws" style="--feature-color:#e87e4d">Jaws</button>
<button class="feature-button" data-feature="four limbs" style="--feature-color:#527fd4">Four limbs</button>
<button class="feature-button" data-feature="amniotic egg" style="--feature-color:#a66bc4">Amniotic egg</button>
<button class="feature-button" data-feature="feathers" style="--feature-color:#d9a52f">Feathers</button>
<button class="feature-button" data-feature="hair" style="--feature-color:#d9667d">Hair</button>
<button class="feature-button" data-feature="scales" style="--feature-color:#5b9b73">Scales</button>
<button class="feature-button" data-feature="bony skeleton" style="--feature-color:#319c9a">Bony skeleton</button>
</div>
<div id="feature-stat">Showing all seven living lineages.</div>
<p class="caution">
Shared traits can be inherited from common ancestors or evolve independently. A feature overlay never converts a living tip into an ancestor.
</p>
<div class="toggle-row">
<button id="labels-button" class="small-button">Hide labels</button>
<button id="reset-button" class="small-button">Reset view</button>
</div>
</aside>
<div class="legend">
<div class="legend-item"><span class="legend-shape"></span> Inferred ancestor</div>
<div class="legend-item"><span class="legend-shape living"></span> Living tip</div>
<div class="legend-item"><span class="legend-shape branch"></span> Branch relationship</div>
</div>
<div class="hint">Drag to orbit · Shift/right-drag to pan · Scroll to zoom · Click a specimen</div>
<div id="loading">Building voxel tree…</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("#view");
const labelsContainer = document.querySelector("#labels");
const selectionTitle = document.querySelector("#selection-title");
const selectionStatus = document.querySelector("#selection-status");
const selectionDescription = document.querySelector("#selection-description");
const selectionFacts = document.querySelector("#selection-facts");
const selectionTraits = document.querySelector("#selection-traits");
const featureStat = document.querySelector("#feature-stat");
const traitMeta = {
"jaws": { label: "Jaws", color: "#e87e4d" },
"four limbs": { label: "Four limbs", color: "#527fd4" },
"amniotic egg": { label: "Amniotic egg", color: "#a66bc4" },
"feathers": { label: "Feathers", color: "#d9a52f" },
"hair": { label: "Hair", color: "#d9667d" },
"scales": { label: "Scales", color: "#5b9b73" },
"bony skeleton": { label: "Bony skeleton", color: "#319c9a" },
"gills": { label: "Gills", color: "#4893b1" },
"cartilage": { label: "Cartilage", color: "#82939b" },
"fins": { label: "Fins", color: "#3b91ad" },
"lobed fins": { label: "Lobed fins", color: "#367d83" },
"moist skin": { label: "Moist skin", color: "#62a98e" }
};
const taxa = [
{
id: "shark",
name: "Shark",
scientific: "Chondrichthyes",
color: "#607b8d",
accent: "#bed7dc",
tip: [-4.7, -2.2, 0],
side: -1,
traits: ["jaws", "gills", "cartilage"],
sister: "the bony-vertebrate clade",
description: "A living cartilaginous fish. Its jaw is shared with the other sampled vertebrates, while cartilage, gills and fin form distinguish this lineage."
},
{
id: "rayfin",
name: "Ray-finned fish",
scientific: "Actinopterygii",
color: "#e8953e",
accent: "#ffd078",
tip: [-4.7, -0.45, 0],
side: -1,
traits: ["jaws", "bony skeleton", "fins"],
sister: "the lobe-finned vertebrate clade",
description: "A living ray-finned fish with jaws, a bony skeleton and fins. It branches beside—not below—the lobe-finned lineage."
},
{
id: "coelacanth",
name: "Coelacanth",
scientific: "Actinistia",
color: "#3e9690",
accent: "#8cc9bc",
tip: [-4.7, 1.0, 0],
side: -1,
traits: ["jaws", "bony skeleton", "lobed fins"],
sister: "the tetrapod clade",
description: "A living lobe-finned vertebrate. The paired, fleshy fins illustrate a close structural relationship to tetrapods without making this animal a tetrapod ancestor."
},
{
id: "amphibian",
name: "Frog",
scientific: "Tetrapoda: Amphibia",
color: "#73a951",
accent: "#c5db77",
tip: [-4.7, 2.65, 0],
side: -1,
traits: ["jaws", "four limbs", "moist skin"],
sister: "the amniote clade",
description: "A living amphibian. Four limbs and jaws connect it to larger branches of the tree, while moist skin characterizes this sampled lineage."
},
{
id: "mammal",
name: "Red fox",
scientific: "Mammalia",
color: "#cb6658",
accent: "#f1ad94",
tip: [4.7, 2.05, 0],
side: 1,
traits: ["jaws", "four limbs", "amniotic egg", "hair"],
sister: "the sauropsid clade",
description: "A living mammal. Hair identifies the sampled mammalian lineage, while jaws, four limbs and the amniotic egg connect it with tetrapods and amniotes."
},
{
id: "turtle",
name: "Turtle",
scientific: "Testudines",
color: "#75884b",
accent: "#b7bb75",
tip: [4.7, 4.55, 0],
side: 1,
traits: ["jaws", "four limbs", "amniotic egg", "scales"],
sister: "the bird lineage",
description: "A living sauropsid with jaws, four limbs and an amniotic egg. Its shell is a highly modified region of the ancestral reptile body plan."
},
{
id: "bird",
name: "Bird",
scientific: "Aves",
color: "#d9aa35",
accent: "#f4d675",
tip: [4.7, 6.05, 0],
side: 1,
traits: ["jaws", "four limbs", "amniotic egg", "scales", "feathers"],
sister: "the turtle lineage",
description: "A living bird. Feathers distinguish this sampled lineage, while jaws, four limbs and the amniotic egg connect it with the sauropsid branch."
}
];
const taxonById = Object.fromEntries(taxa.map(t => [t.id, t]));
const nodes = [
{
id: "root",
name: "Vertebrate root",
short: "Vertebrate root",
pos: [0, -4.35, 0],
contains: taxa.map(t => t.id),
description: "A hypothetical common ancestor of all seven sampled living lineages. This node represents ancestry, not a fossil specimen and not one of the living tips."
},
{
id: "jawed",
name: "Jawed vertebrate ancestor",
short: "Jawed ancestor",
pos: [0, -2.6, 0],
contains: taxa.filter(t => t.id !== "shark").map(t => t.id),
description: "The reconstructed common ancestor of the shark and all bony-vertebrate lineages shown. Jaws occur on every branch above this node."
},
{
id: "osteichthyan",
name: "Bony vertebrate ancestor",
short: "Bony ancestor",
pos: [0, -1.4, 0],
contains: ["rayfin", "coelacanth", "amphibian", "mammal", "turtle", "bird"],
description: "A hypothetical common ancestor of the ray-finned fish and the lobe-finned vertebrate group, including tetrapods."
},
{
id: "sarcopterygian",
name: "Lobe-finned vertebrate ancestor",
short: "Lobe-fin ancestor",
pos: [0, 0, 0],
contains: ["coelacanth", "amphibian", "mammal", "turtle", "bird"],
description: "A reconstructed ancestor shared by the living coelacanth and tetrapods. Its descendants include very different modern forms."
},
{
id: "tetrapod",
name: "Tetrapod ancestor",
short: "Tetrapod ancestor",
pos: [0, 1.4, 0],
contains: ["amphibian", "mammal", "turtle", "bird"],
description: "A hypothetical common ancestor of the sampled amphibians and amniotes. Four limbs is a shared structural feature in the living descendants above this node."
},
{
id: "amniote",
name: "Amniote ancestor",
short: "Amniote ancestor",
pos: [0, 3.0, 0],
contains: ["mammal", "turtle", "bird"],
description: "A reconstructed common ancestor of mammals and sauropsids. The amniotic egg is the shared feature highlighted for these living lineages."
},
{
id: "sauropsid",
name: "Sauropsid ancestor",
short: "Sauropsid ancestor",
pos: [1.2, 4.0, 0],
contains: ["turtle", "bird"],
description: "A hypothetical common ancestor of the living turtle and bird lineages. The two sampled tips are sister lineages here."
}
];
const nodeById = Object.fromEntries(nodes.map(n => [n.id, n]));
const branches = [
{ from: "root", to: "jawed", taxa: taxa.map(t => t.id) },
{ from: "jawed", to: "shark", taxa: ["shark"] },
{ from: "jawed", to: "osteichthyan", taxa: ["rayfin", "coelacanth", "amphibian", "mammal", "turtle", "bird"] },
{ from: "osteichthyan", to: "rayfin", taxa: ["rayfin"] },
{ from: "osteichthyan", to: "sarcopterygian", taxa: ["coelacanth", "amphibian", "mammal", "turtle", "bird"] },
{ from: "sarcopterygian", to: "coelacanth", taxa: ["coelacanth"] },
{ from: "sarcopterygian", to: "tetrapod", taxa: ["amphibian", "mammal", "turtle", "bird"] },
{ from: "tetrapod", to: "amphibian", taxa: ["amphibian"] },
{ from: "tetrapod", to: "amniote", taxa: ["mammal", "turtle", "bird"] },
{ from: "amniote", to: "mammal", taxa: ["mammal"] },
{ from: "amniote", to: "sauropsid", taxa: ["turtle", "bird"] },
{ from: "sauropsid", to: "turtle", taxa: ["turtle"] },
{ from: "sauropsid", to: "bird", taxa: ["bird"] }
];
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf4f0e5);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
const camera = new THREE.OrthographicCamera(-12, 12, 8.5, -8.5, 0.1, 100);
const target = new THREE.Vector3(0, 0.65, 0);
const spherical = { theta: 0.28, phi: 1.18, radius: 28 };
const hemi = new THREE.HemisphereLight(0xfff9e9, 0x7f9187, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff4d9, 3.4);
key.position.set(-7, 12, 10);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -13;
key.shadow.camera.right = 13;
key.shadow.camera.top = 13;
key.shadow.camera.bottom = -13;
key.shadow.camera.near = 1;
key.shadow.camera.far = 40;
key.shadow.bias = -0.0005;
scene.add(key);
const rim = new THREE.DirectionalLight(0xb9e7de, 1.3);
rim.position.set(10, 4, -8);
scene.add(rim);
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const branchMaterials = [];
const nodeMarkers = [];
const tipMarkers = [];
const labelEntries = [];
const clickableObjects = [];
let selectedId = "mammal";
let activeFeature = "all";
function makeBox(parent, w, h, d, x, y, z, color, options = {}) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0.02,
flatShading: true,
transparent: false,
opacity: 1
});
material.userData.baseColor = new THREE.Color(color);
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
if (options.rotation) mesh.rotation.set(...options.rotation);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeVoxelBranch(start, end, descendantTaxa) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: 0x42685f,
roughness: 0.92,
metalness: 0,
flatShading: true,
transparent: false,
opacity: 1
});
material.userData.baseColor = new THREE.Color(0x42685f);
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const length = a.distanceTo(b);
const count = Math.max(2, Math.ceil(length / 0.24));
for (let i = 0; i <= count; i++) {
const p = a.clone().lerp(b, i / count);
const cube = new THREE.Mesh(unitBox, material);
cube.scale.set(0.28, 0.28, 0.28);
cube.position.copy(p);
cube.castShadow = true;
cube.receiveShadow = true;
group.add(cube);
}
group.userData.selectId = descendantTaxa.length === 1
? descendantTaxa[0]
: nodes.find(n => n.contains.length === descendantTaxa.length && n.contains.every(id => descendantTaxa.includes(id)))?.id;
branchMaterials.push({
material,
taxa: descendantTaxa,
baseColor: new THREE.Color(0x42685f)
});
scene.add(group);
return group;
}
function makeAncestorNode(node) {
const group = new THREE.Group();
group.position.set(...node.pos);
group.userData.selectId = node.id;
const material = new THREE.MeshStandardMaterial({
color: 0xd8953f,
roughness: 0.8,
metalness: 0,
flatShading: true,
transparent: false,
opacity: 1
});
material.userData.baseColor = new THREE.Color(0xd8953f);
makeBox(group, 0.56, 0.56, 0.56, 0, 0, 0, 0xd8953f).material = material;
makeBox(group, 0.22, 0.22, 0.22, -0.35, 0.25, 0.02, 0xe3a754).material = material;
makeBox(group, 0.22, 0.22, 0.22, 0.35, -0.25, 0.02, 0xc98132).material = material;
makeBox(group, 0.18, 0.18, 0.18, 0.34, 0.31, 0.02, 0xe6ae61).material = material;
makeBox(group, 0.18, 0.18, 0.18, -0.34, -0.31, 0.02, 0xc98132).material = material;
group.traverse(child => {
if (child.isMesh) {
child.material = material;
child.castShadow = true;
child.receiveShadow = true;
}
});
scene.add(group);
clickableObjects.push(group);
nodeMarkers.push({ node, group, material });
const label = document.createElement("div");
label.className = "node-label";
label.textContent = `${node.short} · ancestor`;
labelsContainer.appendChild(label);
const offsetX = ["root", "jawed", "sarcopterygian", "amniote"].includes(node.id) ? -42 : 42;
labelEntries.push({
element: label,
position: new THREE.Vector3(node.pos[0] + offsetX / 35, node.pos[1] + 0.18, 0.35),
kind: "node",
id: node.id
});
}
function makeDisplayRail(taxon, modelPosition) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: 0xa8aaa0,
transparent: true,
opacity: 0.38
});
const start = new THREE.Vector3(taxon.tip[0], taxon.tip[1], 0);
const end = new THREE.Vector3(modelPosition[0] - taxon.side * 0.92, modelPosition[1], 0);
const length = start.distanceTo(end);
const count = Math.max(2, Math.floor(length / 0.28));
for (let i = 0; i <= count; i++) {
const p = start.clone().lerp(end, i / count);
const cube = new THREE.Mesh(unitBox, material);
cube.scale.set(0.075, 0.075, 0.075);
cube.position.copy(p);
group.add(cube);
}
scene.add(group);
}
function makeTipMarker(taxon) {
const group = new THREE.Group();
group.position.set(...taxon.tip);
group.userData.selectId = taxon.id;
const material = new THREE.MeshStandardMaterial({
color: 0x19a98d,
roughness: 0.72,
flatShading: true,
transparent: false,
opacity: 1
});
material.userData.baseColor = new THREE.Color(0x19a98d);
const haloMaterial = new THREE.MeshBasicMaterial({
color: taxon.color,
transparent: true,
opacity: 0
});
const core = makeBox(group, 0.48, 0.48, 0.48, 0, 0, 0, 0x19a98d);
core.material = material;
const corners = [
[-0.41, 0], [0.41, 0], [0, -0.41], [0, 0.41]
];
corners.forEach(([x, y]) => {
const c = makeBox(group, 0.14, 0.14, 0.14, x, y, 0.02, taxon.color, { castShadow: false });
c.material = haloMaterial;
});
group.traverse(child => {
if (child.isMesh) child.userData.tipId = taxon.id;
});
scene.add(group);
clickableObjects.push(group);
tipMarkers.push({ taxon, group, material, haloMaterial });
const label = document.createElement("div");
label.className = "tip-label";
label.innerHTML = `
<span class="dot" style="background:${taxon.color}; box-shadow:0 0 0 3px ${taxon.color}22"></span>
<span><strong>${taxon.name}</strong><small>Living tip</small></span>
`;
label.addEventListener("click", () => selectEntity(taxon.id));
labelsContainer.appendChild(label);
labelEntries.push({
element: label,
position: new THREE.Vector3(...taxon.tip).add(new THREE.Vector3(0, 0.85, 0)),
kind: "tip",
id: taxon.id
});
}
// Model construction helpers
function addEye(group, x, y, z, size = 0.12) {
makeBox(group, size, size, size, x, y, z, 0x172321, { castShadow: false });
}
function buildFish(taxon, kind) {
const group = new THREE.Group();
const face = -taxon.side;
const f = p => p * face;
if (kind === "shark") {
makeBox(group, 1.75, 0.56, 0.65, 0, 0, 0, taxon.color);
makeBox(group, 1.25, 0.18, 0.58, f(-0.05), -0.25, 0, taxon.accent);
makeBox(group, 0.78, 0.68, 0.73, f(0.93), 0.02, 0, taxon.color);
makeBox(group, 0.33, 0.38, 0.48, f(1.42), -0.03, 0, taxon.accent);
makeBox(group, 0.28, 0.8, 0.18, f(-1.08), 0.05, 0, taxon.color);
makeBox(group, 0.68, 0.62, 0.15, f(-0.16), 0.53, 0, taxon.color);
makeBox(group, 0.58, 0.13, 0.48, f(0.12), -0.16, 0.42, taxon.accent);
makeBox(group, 0.58, 0.13, 0.48, f(0.12), -0.16, -0.42, taxon.accent);
addEye(group, f(1.04), 0.17, 0.38, 0.11);
addEye(group, f(1.04), 0.17, -0.38, 0.11);
} else if (kind === "rayfin") {
makeBox(group, 1.48, 0.43, 0.5, 0, 0, 0, taxon.color);
makeBox(group, 0.95, 0.14, 0.43, f(0.02), -0.2, 0, taxon.accent);
makeBox(group, 0.62, 0.52, 0.58, f(0.78), 0.02, 0, taxon.color);
makeBox(group, 0.25, 0.78, 0.14, f(-0.92), 0.12, 0, taxon.accent);
makeBox(group, 0.24, 0.5, 0.12, f(-0.92), 0.38, 0, taxon.color);
makeBox(group, 0.24, 0.5, 0.12, f(-0.92), -0.14, 0, taxon.color);
makeBox(group, 0.45, 0.4, 0.12, f(-0.08), 0.4, 0, taxon.color);
makeBox(group, 0.5, 0.1, 0.38, f(0.04), -0.08, 0.37, taxon.accent);
addEye(group, f(0.91), 0.12, 0.29, 0.1);
addEye(group, f(0.91), 0.12, -0.29, 0.1);
} else {
makeBox(group, 1.62, 0.76, 0.72, 0, 0, 0, taxon.color);
makeBox(group, 1.05, 0.18, 0.64, f(-0.08), -0.31, 0, taxon.accent);
makeBox(group, 0.62, 0.65, 0.66, f(0.85), 0.03, 0, taxon.color);
makeBox(group, 0.25, 0.65, 0.2, f(-1.02), 0.08, 0, taxon.accent);
makeBox(group, 0.56, 0.48, 0.18, f(-0.1), 0.53, 0, taxon.color);
makeBox(group, 0.55, 0.16, 0.56, f(0.05), -0.24, 0.49, taxon.accent);
makeBox(group, 0.55, 0.16, 0.56, f(0.05), -0.24, -0.49, taxon.accent);
makeBox(group, 0.38, 0.32, 0.18, f(0.4), -0.32, 0.44, taxon.accent);
makeBox(group, 0.38, 0.32, 0.18, f(0.4), -0.32, -0.44, taxon.accent);
addEye(group, f(0.98), 0.17, 0.33, 0.11);
addEye(group, f(0.98), 0.17, -0.33, 0.11);
}
return group;
}
function buildFrog(taxon) {
const group = new THREE.Group();
const face = -taxon.side;
const f = p => p * face;
makeBox(group, 1.18, 0.62, 0.84, 0, 0, 0, taxon.color);
makeBox(group, 0.9, 0.18, 0.72, f(0.05), -0.28, 0, taxon.accent);
makeBox(group, 0.84, 0.52, 0.88, f(0.7), 0.02, 0, taxon.color);
makeBox(group, 0.7, 0.08, 0.76, f(0.8), -0.14, 0, 0x445b35);
makeBox(group, 0.74, 0.24, 0.28, f(-0.32), -0.18, 0.5, taxon.color);
makeBox(group, 0.74, 0.24, 0.28, f(-0.32), -0.18, -0.5, taxon.color);
makeBox(group, 0.65, 0.2, 0.24, f(-0.73), -0.38, 0.56, taxon.accent);
makeBox(group, 0.65, 0.2, 0.24, f(-0.73), -0.38, -0.56, taxon.accent);
makeBox(group, 0.58, 0.2, 0.22, f(0.47), -0.25, 0.43, taxon.color);
makeBox(group, 0.58, 0.2, 0.22, f(0.47), -0.25, -0.43, taxon.color);
makeBox(group, 0.24, 0.3, 0.25, f(0.82), 0.38, 0.28, taxon.accent);
makeBox(group, 0.24, 0.3, 0.25, f(0.82), 0.38, -0.28, taxon.accent);
addEye(group, f(0.91), 0.43, 0.28, 0.15);
addEye(group, f(0.91), 0.43, -0.28, 0.15);
return group;
}
function buildMammal(taxon) {
const group = new THREE.Group();
const face = -taxon.side;
const f = p => p * face;
makeBox(group, 1.28, 0.67, 0.68, 0, 0.08, 0, taxon.color);
makeBox(group, 0.62, 0.64, 0.62, f(0.82), 0.2, 0, taxon.color);
makeBox(group, 0.3, 0.22, 0.42, f(1.15), 0.08, 0, taxon.accent);
makeBox(group, 0.23, 0.42, 0.2, f(0.72), 0.68, 0.22, taxon.color);
makeBox(group, 0.23, 0.42, 0.2, f(0.72), 0.68, -0.22, taxon.color);
makeBox(group, 0.16, 0.17, 0.17, f(0.72), 0.9, 0.22, 0x70433a);
makeBox(group, 0.16, 0.17, 0.17, f(0.72), 0.9, -0.22, 0x70433a);
makeBox(group, 0.24, 0.48, 0.22, f(-0.42), -0.35, 0.25, taxon.color);
makeBox(group, 0.24, 0.48, 0.22, f(-0.42), -0.35, -0.25, taxon.color);
makeBox(group, 0.24, 0.48, 0.22, f(0.38), -0.35, 0.25, taxon.color);
makeBox(group, 0.24, 0.48, 0.22, f(0.38), -0.35, -0.25, taxon.color);
makeBox(group, 0.65, 0.25, 0.28, f(-0.91), 0.04, 0.17, taxon.color);
makeBox(group, 0.65, 0.25, 0.28, f(-0.91), 0.04, -0.17, taxon.color);
makeBox(group, 0.34, 0.3, 0.32, f(-1.28), 0.02, 0, taxon.accent);
addEye(group, f(0.97), 0.32, 0.31, 0.11);
addEye(group, f(0.97), 0.32, -0.31, 0.11);
makeBox(group, 0.12, 0.1, 0.14, f(1.29), 0.03, 0, 0x392d2a);
return group;
}
function buildTurtle(taxon) {
const group = new THREE.Group();
const face = -taxon.side;
const f = p => p * face;
makeBox(group, 1.35, 0.62, 1.0, 0, 0.04, 0, taxon.color);
makeBox(group, 1.08, 0.13, 0.82, 0, 0.39, 0, taxon.accent);
makeBox(group, 0.28, 0.28, 0.28, -0.25, 0.44, -0.18, 0x5b713a);
makeBox(group, 0.28, 0.28, 0.28, 0.25, 0.44, 0.18, 0x5b713a);
makeBox(group, 0.46, 0.39, 0.43, f(0.84), -0.02, 0, taxon.color);
makeBox(group, 0.17, 0.16, 0.17, f(1.08), 0.01, 0, 0x536b39);
makeBox(group, 0.55, 0.22, 0.28, f(-0.48), -0.35, 0.5, taxon.color);
makeBox(group, 0.55, 0.22, 0.28, f(-0.48), -0.35, -0.5, taxon.color);
makeBox(group, 0.55, 0.22, 0.28, f(0.48), -0.35, 0.5, taxon.color);
makeBox(group, 0.55, 0.22, 0.28, f(0.48), -0.35, -0.5, taxon.color);
makeBox(group, 0.36, 0.16, 0.2, f(-0.87), -0.05, 0, taxon.accent);
addEye(group, f(1.02), 0.1, 0.2, 0.09);
addEye(group, f(1.02), 0.1, -0.2, 0.09);
return group;
}
function buildBird(taxon) {
const group = new THREE.Group();
const face = -taxon.side;
const f = p => p * face;
makeBox(group, 0.9, 0.88, 0.64, 0, 0.05, 0, taxon.color);
makeBox(group, 0.58, 0.58, 0.55, f(0.59), 0.61, 0, taxon.color);
makeBox(group, 0.35, 0.2, 0.3, f(0.98), 0.55, 0, 0xd8743f);
makeBox(group, 0.7, 0.64, 0.14, -0.05, 0.07, 0.4, taxon.accent);
makeBox(group, 0.7, 0.64, 0.14, -0.05, 0.07, -0.4, taxon.accent);
makeBox(group, 0.62, 0.16, 0.34, f(-0.69), 0.01, 0, 0x8d6930);
makeBox(group, 0.65, 0.16, 0.34, f(-0.69), 0.01, 0, 0x9b7536);
makeBox(group, 0.3, 0.16, 0.2, f(-0.22), 0.94, 0, 0xbd8130);
makeBox(group, 0.18, 0.36, 0.2, f(0.47), -0.42, 0.2, 0x9b7536);
makeBox(group, 0.18, 0.36, 0.2, f(0.47), -0.42, -0.2, 0x9b7536);
addEye(group, f(0.74), 0.73, 0.28, 0.11);
addEye(group, f(0.74), 0.73, -0.28, 0.11);
return group;
}
function addExhibitPedestal(group) {
makeBox(group, 1.92, 0.13, 1.5, 0, -0.9, 0, 0xdedbd0, { castShadow: false });
makeBox(group, 0.12, 0.52, 0.12, 0, -0.63, 0, 0xaeb5ab, { castShadow: false });
}
// Ground and spatial grid
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 34),
new THREE.MeshStandardMaterial({ color: 0xeae6da, roughness: 1 })
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -5.15;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 17, 0x9aa69f, 0xb8beb5);
grid.position.y = -5.12;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
// Build tree branches
branches.forEach(branch => {
const startId = branch.from;
const endId = branch.to;
const start = nodes.find(n => n.id === startId)?.pos || taxonById[endId].tip;
const end = nodes.find(n => n.id === endId)?.pos || taxonById[endId].tip;
makeVoxelBranch(start, end, branch.taxa);
});
nodes.forEach(makeAncestorNode);
// Build the seven living specimens around the central tree.
taxa.forEach(taxon => {
const modelPosition = [
taxon.tip[0] + taxon.side * 2.25,
taxon.tip[1],
0
];
let model;
if (taxon.id === "shark") model = buildFish(taxon, "shark");
else if (taxon.id === "rayfin") model = buildFish(taxon, "rayfin");
else if (taxon.id === "coelacanth") model = buildFish(taxon, "coelacanth");
else if (taxon.id === "amphibian") model = buildFrog(taxon);
else if (taxon.id === "mammal") model = buildMammal(taxon);
else if (taxon.id === "turtle") model = buildTurtle(taxon);
else model = buildBird(taxon);
addExhibitPedestal(model);
model.position.set(...modelPosition);
model.scale.setScalar(0.9);
model.userData.selectId = taxon.id;
scene.add(model);
clickableObjects.push(model);
const materials = [];
model.traverse(child => {
if (child.isMesh) {
child.material.userData.baseColor = child.material.color.clone();
materials.push(child.material);
}
});
taxon.model = model;
taxon.modelPosition = modelPosition;
taxon.modelMaterials = materials;
makeDisplayRail(taxon, modelPosition);
makeTipMarker(taxon);
});
// ---------------------------------------------------------------------
// UI and filtering
// ---------------------------------------------------------------------
const indexContainer = document.querySelector("#taxon-index");
taxa.forEach(taxon => {
const button = document.createElement("button");
button.className = "index-button";
button.dataset.taxon = taxon.id;
button.innerHTML = `<span style="background:${taxon.color}"></span>${taxon.name}`;
button.addEventListener("click", () => selectEntity(taxon.id));
indexContainer.appendChild(button);
});
function fact(text) {
const div = document.createElement("div");
div.className = "fact";
div.textContent = text;
return div;
}
function selectEntity(id) {
selectedId = id;
if (taxonById[id]) {
const taxon = taxonById[id];
selectionTitle.textContent = taxon.name;
selectionStatus.textContent = "Living tip";
selectionStatus.className = "status-pill living";
selectionDescription.textContent = taxon.description;
selectionFacts.replaceChildren(
fact(`${taxon.scientific} · sampled living lineage`),
fact(`Sister group: ${taxon.sister}`),
fact(`${taxon.traits.length} shared or distinguishing feature tags`)
);
selectionTraits.replaceChildren();
taxon.traits.forEach(trait => {
const meta = traitMeta[trait];
const tag = document.createElement("span");
tag.className = "trait-tag";
tag.style.setProperty("--trait-color", meta.color);
tag.innerHTML = `<i></i>${meta.label}`;
selectionTraits.appendChild(tag);
});
} else {
const node = nodeById[id];
selectionTitle.textContent = node.name;
selectionStatus.textContent = "Inferred ancestor";
selectionStatus.className = "status-pill ancestor";
selectionDescription.textContent = node.description;
selectionFacts.replaceChildren(
fact("Reconstructed ancestral node, not a sampled fossil"),
fact(`Contains ${node.contains.length} sampled living lineages`),
fact("Represents the most recent common ancestor of its descendants")
);
selectionTraits.replaceChildren();
const descendants = node.contains.map(id => taxonById[id].name).join(" · ");
const tag = document.createElement("span");
tag.className = "trait-tag";
tag.style.setProperty("--trait-color", "#d8953f");
tag.textContent = descendants;
selectionTraits.appendChild(tag);
}
document.querySelectorAll(".index-button").forEach(button => {
button.classList.toggle("active", button.dataset.taxon === id);
});
labelEntries.forEach(entry => {
entry.element.classList.toggle("selected", entry.id === id && entry.kind === "tip");
});
}
function setMaterialOpacity(material, opacity) {
material.opacity = opacity;
material.transparent = opacity < 0.999;
material.depthWrite = opacity > 0.35;
}
function applyFeature(feature) {
activeFeature = feature;
const featureColor = feature === "all" ? null : new THREE.Color(traitMeta[feature].color);
let matchCount = 0;
taxa.forEach(taxon => {
const matches = feature === "all" || taxon.traits.includes(feature);
if (matches) matchCount++;
taxon.modelMaterials.forEach(material => {
const baseColor = material.userData.baseColor;
material.color.copy(baseColor);
setMaterialOpacity(material, matches ? 1 : 0.14);
material.emissive.set(0x000000);
if (feature !== "all" && matches) {
material.emissive.copy(featureColor);
material.emissiveIntensity = 0.075;
}
});
const tip = tipMarkers.find(marker => marker.taxon.id === taxon.id);
setMaterialOpacity(tip.material, matches ? 1 : 0.17);
tip.haloMaterial.color.copy(feature === "all" ? new THREE.Color(taxon.color) : featureColor);
tip.haloMaterial.opacity = feature === "all" ? 0 : (matches ? 0.95 : 0);
labelEntries
.filter(entry => entry.id === taxon.id && entry.kind === "tip")
.forEach(entry => entry.element.classList.toggle("dim", !matches));
});
branchMaterials.forEach(record => {
const matches = feature === "all" || record.taxa.some(id => taxonById[id].traits.includes(feature));
record.material.color.copy(feature === "all" ? record.baseColor : featureColor);
setMaterialOpacity(record.material, feature === "all" ? 1 : (matches ? 0.96 : 0.10));
record.material.emissive.set(0x000000);
if (feature !== "all" && matches) {
record.material.emissive.copy(featureColor);
record.material.emissiveIntensity = 0.11;
}
});
nodeMarkers.forEach(marker => {
const matches = feature === "all" || marker.node.contains.some(id => taxonById[id].traits.includes(feature));
marker.material.color.copy(feature === "all" ? marker.material.userData.baseColor : featureColor);
setMaterialOpacity(marker.material, feature === "all" ? 1 : (matches ? 1 : 0.12));
marker.material.emissive.set(0x000000);
if (feature !== "all" && matches) {
marker.material.emissive.copy(featureColor);
marker.material.emissiveIntensity = 0.14;
}
labelEntries
.filter(entry => entry.id === marker.node.id && entry.kind === "node")
.forEach(entry => entry.element.classList.toggle("dim", !matches));
});
document.querySelectorAll(".feature-button").forEach(button => {
button.classList.toggle("active", button.dataset.feature === feature);
});
if (feature === "all") {
featureStat.textContent = "Showing all seven living lineages.";
} else {
featureStat.textContent = `${matchCount} of 7 living lineages possess ${traitMeta[feature].label.toLowerCase()}. Highlighted branches lead toward matching tips.`;
}
}
document.querySelectorAll(".feature-button").forEach(button => {
button.addEventListener("click", () => applyFeature(button.dataset.feature));
});
// ---------------------------------------------------------------------
// Camera controls implemented directly, without addons.
// ---------------------------------------------------------------------
let viewHeight = 17.5;
let cameraZoom = 1;
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
const aspect = width / height;
viewHeight = aspect < 0.8 ? 27 : (aspect < 1.2 ? 21 : 17.5);
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.left = -(viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
updateCamera();
}
function updateCamera() {
const sinPhi = Math.sin(spherical.phi);
camera.position.set(
target.x + spherical.radius * sinPhi * Math.sin(spherical.theta),
target.y + spherical.radius * Math.cos(spherical.phi),
target.z + spherical.radius * sinPhi * Math.cos(spherical.theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetView() {
target.set(0, 0.65, 0);
spherical.theta = 0.28;
spherical.phi = 1.18;
cameraZoom = 1;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
updateCamera();
}
document.querySelector("#reset-button").addEventListener("click", resetView);
const labelsButton = document.querySelector("#labels-button");
labelsButton.addEventListener("click", () => {
const hidden = labelsContainer.classList.toggle("labels-off");
labelsButton.textContent = hidden ? "Show labels" : "Hide labels";
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointers = new Map();
let dragMode = "orbit";
let moved = 0;
let lastPinchDistance = 0;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function findSelectable(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickableObjects, true);
if (!hits.length) return null;
let object = hits[0].object;
while (object && !object.userData.selectId) object = object.parent;
return object?.userData?.selectId || null;
}
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
moved = 0;
dragMode = event.button === 2 || event.shiftKey ? "pan" : "orbit";
canvas.classList.add("grabbing");
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
lastPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) {
const selectable = findSelectable(event);
canvas.classList.toggle("pickable", !!selectable);
return;
}
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
moved += Math.abs(dx) + Math.abs(dy);
if (pointers.size >= 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (lastPinchDistance > 0) {
cameraZoom = THREE.MathUtils.clamp(cameraZoom * (distance / lastPinchDistance), 0.65, 2.6);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
lastPinchDistance = distance;
return;
}
if (dragMode === "orbit") {
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(spherical.phi - dy * 0.005, 0.48, 1.48);
spherical.theta = THREE.MathUtils.clamp(spherical.theta, -1.08, 1.08);
updateCamera();
} else {
const unitsPerPixel = (camera.top - camera.bottom) / camera.zoom / canvas.clientHeight;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 1);
target.addScaledVector(right, -dx * unitsPerPixel);
target.addScaledVector(up, dy * unitsPerPixel);
updateCamera();
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
if (pointers.size === 0) {
canvas.classList.remove("grabbing");
if (moved < 6) {
const selectable = findSelectable(event);
if (selectable) selectEntity(selectable);
}
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(cameraZoom * Math.exp(-event.deltaY * 0.001), 0.65, 2.6);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}, { passive: false });
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Labels and render loop
// ---------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
labelEntries.forEach(entry => {
projected.copy(entry.position).project(camera);
const visible = projected.z > -1 && projected.z < 1 &&
projected.x > -1.2 && projected.x < 1.2 &&
projected.y > -1.2 && projected.y < 1.2;
entry.element.style.display = visible ? "" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
entry.element.style.transform = `translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
});
}
function animate(time) {
const pulse = 1 + Math.sin(time * 0.0035) * 0.045;
tipMarkers.forEach(marker => {
if (activeFeature !== "all" && marker.haloMaterial.opacity > 0) {
marker.group.scale.setScalar(pulse);
} else {
marker.group.scale.setScalar(1);
}
});
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
updateCamera();
selectEntity(selectedId);
applyFeature("all");
animate(0);
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
setTimeout(() => document.querySelector("#loading").remove(), 300);
});
</script>
</body>
</html>
```