Prompt specification
Build or customize the Three.js 3D scene "Comparative anatomy teaching hall" 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: Comparative anatomy teaching hall
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/comparative-anatomy-teaching-hall-x0919
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows homologous anatomical structures. Compose animal silhouettes with detachable limb skeleton overlays and a branching relationship panel; connect matching structures without implying identical movement or exact anatomical proportions. Voxel style.
Working Three.js Starter (comparative-anatomy-teaching-hall-x0919):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="An interactive voxel atlas showing homologous tetrapod limb structures."
/>
<title>Bone / Branch — Homology Atlas</title>
<style>
:root {
color-scheme: dark;
--bg: #071116;
--panel: #0b171e;
--panel-2: #101f27;
--line: rgba(166, 201, 211, 0.15);
--text: #edf3ef;
--muted: #8ca0a9;
--faint: #5e727b;
--mint: #6ee7d0;
--mint-soft: rgba(110, 231, 208, 0.12);
--orange: #f2a65a;
--shadow: 0 20px 55px rgba(0, 0, 0, 0.32);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overflow: hidden;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--mint);
outline-offset: 3px;
}
#app {
height: 100vh;
min-height: 620px;
display: flex;
flex-direction: column;
}
.topbar {
height: 68px;
flex: 0 0 68px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid var(--line);
background: rgba(7, 17, 22, 0.94);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.voxel-mark {
width: 30px;
height: 30px;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 2px;
transform: rotate(-2deg);
}
.voxel-mark i {
display: block;
background: var(--mint);
opacity: 0.9;
}
.voxel-mark i:nth-child(1),
.voxel-mark i:nth-child(5),
.voxel-mark i:nth-child(9) {
opacity: 0.2;
}
.voxel-mark i:nth-child(2),
.voxel-mark i:nth-child(4) {
opacity: 0.45;
}
.brand-title {
display: flex;
align-items: baseline;
gap: 10px;
white-space: nowrap;
}
.brand-title strong {
font-size: 14px;
letter-spacing: 0.18em;
font-weight: 800;
}
.brand-title span {
color: var(--muted);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.header-meta {
display: flex;
align-items: center;
gap: 18px;
color: var(--muted);
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.header-meta b {
color: var(--mint);
font-weight: 700;
}
.header-dot {
width: 6px;
height: 6px;
display: inline-block;
margin-right: 7px;
background: var(--mint);
box-shadow: 0 0 14px var(--mint);
}
main {
min-height: 0;
flex: 1;
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
}
#stage {
position: relative;
min-width: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 30%, rgba(35, 79, 87, 0.22), transparent 45%),
linear-gradient(180deg, #09151c 0%, #071116 100%);
}
#canvasHost {
position: absolute;
inset: 0;
}
#canvasHost canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#canvasHost canvas:active {
cursor: grabbing;
}
.stage-copy {
position: absolute;
top: 25px;
left: 27px;
z-index: 3;
max-width: 410px;
pointer-events: none;
}
.eyebrow {
margin: 0 0 9px;
color: var(--mint);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.stage-copy h1 {
margin: 0;
font-size: clamp(25px, 3vw, 39px);
line-height: 1.04;
letter-spacing: -0.04em;
font-weight: 760;
}
.stage-copy p:last-child {
max-width: 380px;
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.stage-status {
position: absolute;
top: 26px;
right: 23px;
z-index: 3;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 7px;
pointer-events: none;
font: 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
color: var(--faint);
}
.status-chip {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid var(--line);
background: rgba(8, 18, 24, 0.62);
backdrop-filter: blur(10px);
}
.status-chip strong {
color: var(--text);
font-weight: 600;
}
.controls {
position: absolute;
left: 22px;
bottom: 22px;
z-index: 5;
width: 260px;
padding: 14px;
border: 1px solid var(--line);
background: rgba(8, 18, 24, 0.82);
box-shadow: var(--shadow);
backdrop-filter: blur(16px);
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: var(--muted);
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.reset-button {
padding: 0;
border: 0;
background: none;
color: var(--mint);
cursor: pointer;
font: inherit;
letter-spacing: inherit;
text-transform: inherit;
}
.toggle-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 29px;
color: #c6d1d3;
font-size: 11px;
}
.toggle {
position: relative;
width: 32px;
height: 17px;
flex: 0 0 auto;
}
.toggle input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.toggle span {
position: absolute;
inset: 0;
border: 1px solid #3a4c54;
background: #13232b;
cursor: pointer;
transition: 160ms ease;
}
.toggle span::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 9px;
height: 9px;
background: #71848b;
transition: 160ms ease;
}
.toggle input:checked + span {
border-color: rgba(110, 231, 208, 0.7);
background: var(--mint-soft);
}
.toggle input:checked + span::after {
left: 18px;
background: var(--mint);
}
.range-row {
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid var(--line);
}
.range-label {
display: flex;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 4px;
accent-color: var(--mint);
cursor: pointer;
}
input[type="range"]:disabled {
opacity: 0.3;
cursor: default;
}
.orbit-hint {
position: absolute;
right: 22px;
bottom: 21px;
z-index: 3;
color: var(--faint);
font: 9px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
}
#labels {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
}
.animal-label {
position: absolute;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 8px;
border: 1px solid transparent;
background: rgba(7, 17, 22, 0.75);
color: #a8b7bc;
cursor: pointer;
pointer-events: auto;
transform: translate(-50%, 0);
transition: 140ms ease;
white-space: nowrap;
}
.animal-label:hover,
.animal-label.active {
border-color: rgba(110, 231, 208, 0.35);
color: var(--text);
background: rgba(8, 20, 25, 0.92);
}
.animal-label i {
width: 6px;
height: 6px;
background: var(--species-color);
}
.animal-label strong {
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
}
.animal-label span {
color: var(--faint);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
font-style: italic;
}
#railLabel {
position: absolute;
z-index: 4;
display: none;
padding: 5px 8px;
border: 1px solid rgba(110, 231, 208, 0.28);
background: rgba(7, 17, 22, 0.88);
color: var(--mint);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -50%);
}
aside {
min-height: 0;
overflow-y: auto;
border-left: 1px solid var(--line);
background:
linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 28%),
var(--panel);
scrollbar-width: thin;
scrollbar-color: #31444d transparent;
}
.panel-section {
padding: 21px 21px 20px;
border-bottom: 1px solid var(--line);
}
.panel-section:last-child {
border-bottom: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.section-title h2,
.section-title h3 {
margin: 0;
font-size: 13px;
font-weight: 700;
letter-spacing: -0.01em;
}
.section-title h3 {
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.1em;
}
.tiny-badge {
padding: 4px 6px;
border: 1px solid var(--line);
color: var(--faint);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-intro {
margin: 0 0 13px;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.tree-wrap {
position: relative;
border: 1px solid var(--line);
background: rgba(4, 12, 16, 0.34);
overflow: hidden;
}
#tree {
display: block;
width: 100%;
height: auto;
}
.tree-line {
stroke: #46606a;
stroke-width: 1.2;
fill: none;
}
.tree-node {
fill: #172932;
stroke: #63808a;
stroke-width: 1.2;
}
.tree-label {
fill: #718890;
font: 7.5px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.tree-species {
cursor: pointer;
}
.tree-species circle {
fill: #172932;
stroke: var(--species-color);
stroke-width: 1.5;
}
.tree-species text {
fill: #aab9bd;
font: 8px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.tree-species.active circle {
fill: var(--species-color);
filter: drop-shadow(0 0 5px var(--species-color));
}
.tree-species.active text {
fill: #f4f8f5;
}
.tree-note {
padding: 8px 9px;
border-top: 1px solid var(--line);
color: var(--faint);
font: 8px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
}
.taxon-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-top: 11px;
}
.taxon-choice {
min-width: 0;
padding: 8px 4px;
border: 1px solid var(--line);
background: #0d1b22;
color: var(--muted);
cursor: pointer;
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
text-transform: uppercase;
transition: 140ms ease;
}
.taxon-choice::before {
content: "";
display: block;
width: 6px;
height: 6px;
margin: 0 auto 6px;
background: var(--species-color);
}
.taxon-choice:hover,
.taxon-choice.active {
border-color: var(--species-color);
color: var(--text);
background: #13242c;
}
.limb-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
margin-bottom: 11px;
}
.limb-tab {
padding: 9px 8px;
border: 1px solid var(--line);
background: #0c1a21;
color: var(--muted);
cursor: pointer;
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.limb-tab.active {
border-color: rgba(110, 231, 208, 0.52);
background: var(--mint-soft);
color: var(--mint);
}
.part-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
}
.part-button {
position: relative;
min-height: 50px;
padding: 9px 9px 8px 29px;
border: 1px solid var(--line);
background: #0b1920;
color: #a9b8bc;
cursor: pointer;
text-align: left;
transition: 140ms ease;
}
.part-button span {
position: absolute;
top: 9px;
left: 9px;
color: var(--faint);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.part-button strong {
display: block;
font-size: 10px;
line-height: 1.2;
font-weight: 600;
}
.part-button:hover {
border-color: #45616a;
color: var(--text);
}
.part-button.active {
border-color: rgba(110, 231, 208, 0.7);
background: var(--mint-soft);
color: var(--mint);
}
.part-button.active span {
color: var(--mint);
}
.match-card {
padding: 14px;
border: 1px solid rgba(110, 231, 208, 0.25);
background:
linear-gradient(135deg, rgba(110, 231, 208, 0.08), transparent 70%),
#0b1920;
}
.match-kicker {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin-bottom: 9px;
color: var(--mint);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.match-card h4 {
margin: 0 0 8px;
font-size: 14px;
font-weight: 680;
}
.match-card p {
margin: 0;
color: #9dafb4;
font-size: 10px;
line-height: 1.6;
}
.caution {
margin-top: 15px;
padding: 11px 12px;
border-left: 2px solid var(--orange);
background: rgba(242, 166, 90, 0.07);
color: #b9aaa0;
font-size: 9px;
line-height: 1.55;
}
.caution strong {
display: block;
margin-bottom: 4px;
color: var(--orange);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
@media (max-width: 1000px) {
main {
grid-template-columns: minmax(0, 1fr) 340px;
}
.stage-copy {
max-width: 310px;
}
.stage-copy h1 {
font-size: 28px;
}
.stage-status {
display: none;
}
}
@media (max-width: 760px) {
body {
overflow: auto;
}
#app {
height: auto;
min-height: 100vh;
}
.topbar {
height: 60px;
flex-basis: 60px;
padding: 0 15px;
}
.brand-title span,
.header-meta > span:last-child {
display: none;
}
main {
display: block;
}
#stage {
height: 66vh;
min-height: 490px;
}
aside {
overflow: visible;
border-left: 0;
border-top: 1px solid var(--line);
}
.stage-copy {
top: 18px;
left: 18px;
max-width: 250px;
}
.stage-copy h1 {
font-size: 24px;
}
.stage-copy p:last-child {
display: none;
}
.controls {
left: 12px;
bottom: 12px;
width: 225px;
padding: 11px;
}
.orbit-hint {
right: 12px;
bottom: 13px;
}
.panel-section {
padding: 18px;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="voxel-mark" aria-hidden="true">
<i></i><i></i><i></i>
<i></i><i></i><i></i>
<i></i><i></i><i></i>
</div>
<div class="brand-title">
<strong>BONE / BRANCH</strong>
<span>Comparative homology atlas</span>
</div>
</div>
<div class="header-meta">
<span><b class="header-dot"></b>Interactive specimen</span>
<span>4 taxa · 10 structures</span>
</div>
</header>
<main>
<section id="stage" aria-label="Interactive 3D anatomy comparison">
<div id="canvasHost"></div>
<div class="stage-copy">
<p class="eyebrow">Tetrapod limb homology / 01</p>
<h1>Shared bones.<br />Different lives.</h1>
<p>
Explore inherited limb elements across four animal silhouettes.
Select a structure to reveal its matching elements across the tree.
</p>
</div>
<div class="stage-status">
<div class="status-chip">
<span>Focused taxon</span>
<strong id="focusReadout">Bat</strong>
</div>
<div class="status-chip">
<span>Homology matches</span>
<strong id="matchReadout">4 / 4</strong>
</div>
</div>
<div id="labels"></div>
<div id="railLabel">Homology rail</div>
<div class="controls">
<div class="control-heading">
<span>Overlay controls</span>
<button class="reset-button" id="resetView" type="button">Reset view</button>
</div>
<label class="toggle-row">
<span>Limb skeleton overlay</span>
<span class="toggle">
<input id="bonesToggle" type="checkbox" checked />
<span></span>
</span>
</label>
<label class="toggle-row">
<span>Detach from silhouette</span>
<span class="toggle">
<input id="detachToggle" type="checkbox" checked />
<span></span>
</span>
</label>
<div class="range-row">
<div class="range-label">
<span>Overlay separation</span>
<span id="separationValue">28%</span>
</div>
<input
id="separation"
type="range"
min="0"
max="100"
value="28"
aria-label="Overlay separation"
/>
</div>
</div>
<div class="orbit-hint">
Drag to orbit · Scroll to zoom<br />
Click a bone or silhouette
</div>
</section>
<aside aria-label="Relationship and structure controls">
<section class="panel-section">
<div class="section-title">
<h2>Relationship map</h2>
<span class="tiny-badge">Simplified topology</span>
</div>
<p class="section-intro">
A branching view of the selected taxa. Click a terminal taxon to
focus it in the specimen view.
</p>
<div class="tree-wrap">
<svg id="tree" viewBox="0 0 360 200" role="img" aria-label="Simplified tetrapod relationship tree">
<g class="tree-lines">
<path class="tree-line" d="M18 100 H75" />
<path class="tree-line" d="M75 48 V153" />
<path class="tree-line" d="M75 48 H140" />
<path class="tree-line" d="M75 153 H140" />
<path class="tree-line" d="M140 48 H200" />
<path class="tree-line" d="M200 20 V90" />
<path class="tree-line" d="M200 20 H285" />
<path class="tree-line" d="M200 90 H285" />
<path class="tree-line" d="M285 90 V112" />
<path class="tree-line" d="M285 90 H305" />
<path class="tree-line" d="M285 112 H305" />
</g>
<g class="tree-clades">
<text class="tree-label" x="9" y="92">Tetrapoda</text>
<text class="tree-label" x="78" y="113">Amniota</text>
<text class="tree-label" x="143" y="39">Mammalia</text>
<text class="tree-label" x="143" y="165">Aves</text>
<text class="tree-label" x="203" y="11">Euarchontoglires</text>
<text class="tree-label" x="203" y="105">Laurasiatheria</text>
</g>
<g class="tree-internal-nodes">
<circle class="tree-node" cx="18" cy="100" r="3.5" />
<circle class="tree-node" cx="75" cy="100" r="3" />
<circle class="tree-node" cx="140" cy="48" r="3" />
<circle class="tree-node" cx="140" cy="153" r="3" />
<circle class="tree-node" cx="200" cy="20" r="3" />
<circle class="tree-node" cx="200" cy="90" r="3" />
</g>
<g class="tree-species" data-species="human" style="--species-color:#e7b779">
<circle cx="285" cy="20" r="5" />
<text x="295" y="23">Human</text>
</g>
<g class="tree-species" data-species="bat" style="--species-color:#75d6c7">
<circle cx="285" cy="90" r="5" />
<text x="295" y="93">Bat</text>
</g>
<g class="tree-species" data-species="cat" style="--species-color:#9aa7ff">
<circle cx="285" cy="112" r="5" />
<text x="295" y="115">Cat</text>
</g>
<g class="tree-species" data-species="bird" style="--species-color:#f08d6b">
<circle cx="140" cy="153" r="5" />
<text x="150" y="156">Bird</text>
</g>
</svg>
<div class="tree-note">
Topology only · branch lengths and evolutionary time omitted
</div>
</div>
<div class="taxon-buttons" aria-label="Select a specimen">
<button class="taxon-choice" data-species="human" style="--species-color:#e7b779" type="button">Human</button>
<button class="taxon-choice" data-species="bat" style="--species-color:#75d6c7" type="button">Bat</button>
<button class="taxon-choice" data-species="cat" style="--species-color:#9aa7ff" type="button">Cat</button>
<button class="taxon-choice" data-species="bird" style="--species-color:#f08d6b" type="button">Bird</button>
</div>
</section>
<section class="panel-section">
<div class="section-title">
<h3>Homologous structure</h3>
<span class="tiny-badge">Select to link</span>
</div>
<div class="limb-tabs" role="tablist" aria-label="Limb type">
<button class="limb-tab active" data-limb="fore" type="button">Forelimb</button>
<button class="limb-tab" data-limb="hind" type="button">Hindlimb</button>
</div>
<div id="partGrid" class="part-grid"></div>
</section>
<section class="panel-section">
<div class="match-card">
<div class="match-kicker">
<span id="matchCategory">Forelimb / 01</span>
<span id="matchCount">4 taxa matched</span>
</div>
<h4 id="matchTitle">Humerus</h4>
<p id="matchNote"></p>
</div>
<div class="caution">
<strong>Homology, not identical mechanics</strong>
Links indicate shared ancestry. They do not imply identical movement,
function, or exact proportions. Silhouettes and bone dimensions are
intentionally diagrammatic.
</div>
</section>
</aside>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = (selector) => document.querySelector(selector);
const $$ = (selector) => [...document.querySelectorAll(selector)];
const stage = $("#stage");
const canvasHost = $("#canvasHost");
const labelsHost = $("#labels");
const railLabel = $("#railLabel");
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
canvasHost.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Three-dimensional voxel silhouettes of four tetrapods with selectable limb skeletons"
);
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(36, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.65, 0);
const orbit = {
theta: 0.025,
phi: 1.2,
radius: 17,
userAdjusted: false
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
applyCamera();
const hemisphere = new THREE.HemisphereLight(0xa9dded, 0x071116, 1.65);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffefd9, 3.1);
keyLight.position.set(-5, 10, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x72d9cc, 1.65);
rimLight.position.set(8, 5, -6);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 24),
new THREE.MeshStandardMaterial({
color: 0x071116,
roughness: 0.98,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.13;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(34, 34, 0x31505a, 0x1a3038);
grid.position.y = -0.12;
grid.material.transparent = true;
grid.material.opacity = 0.2;
grid.material.depthWrite = false;
scene.add(grid);
// ------------------------------------------------------------
// Specimen definitions
// Grid silhouettes are deliberately schematic, not proportional.
// ------------------------------------------------------------
const speciesData = [
{
id: "cat",
name: "Cat",
latin: "Felis catus",
x: -5.8,
scale: 0.12,
accent: "#9aa7ff",
grid: [
" HHH ",
" HHHHH TTTTT ",
" HHH TTTTTTTTTTTT ",
" TTTTTTTTTTTTTTTTT ",
" TTTTTTTTTTTTTTTTTTTT ",
" TTTTTTTTTTTTTTTTTTTT ",
" TTTTTTTTTTTTTTTTTT ",
" TTTTTT TTTTTTT ",
" LLLL LLLLLLL ",
" LLLL LLLLLLL ",
" LLL LLLLLLL ",
" LLLL LLLLLLLL ",
" LLLL LLLLLLLL ",
" LLL LLLLLL ",
" ",
" "
],
skeleton: [
["humerus", [24, 7], [24, 10.5]],
["radiusulna", [23.6, 10.5], [23.6, 13]],
["radiusulna", [24.4, 10.5], [24.4, 13]],
["carpals", [24, 13], [24, 14]],
["metacarpals", [24, 14], [24, 15]],
["foreDigits", [24, 15], [24, 17]],
["foreDigits", [24, 15], [25.2, 16.2]],
["femur", [10, 8], [10, 12.7]],
["tibiafibula", [9.6, 12.7], [9.6, 14.7]],
["tibiafibula", [10.4, 12.7], [10.4, 14.7]],
["tarsals", [10, 14.7], [10, 15.2]],
["metatarsals", [10, 15.2], [10, 15.8]],
["hindDigits", [10, 15.8], [11.7, 15.8]],
["hindDigits", [10, 15.8], [9.2, 15.8]]
]
},
{
id: "bird",
name: "Bird",
latin: "Gallus gallus",
x: -1.9,
scale: 0.12,
accent: "#f08d6b",
grid: [
" HHH ",
" HHHHH ",
" HHH ",
" NNN ",
" WWWNNNNNNNN ",
" WWWWWWNNNNNNNNNNNN ",
" WWWWWWWNNNNNNNNNNNNNN ",
" WWWWWWWWNNNNNNNNNNNNNNN ",
" WWWWWWWNNNNNNNNNNNNNN ",
" WWWNNNNNNNNNNNNNNNN ",
" NNNNNNNNNNNNNNNN ",
" NNNNNNNNNNNNNN ",
" NNNNNNNNNNNNN ",
" LLL LLL ",
" LLL LLL ",
" LLL LLL ",
" LLLL LLLL ",
" TT ",
" TTTTTTTTTT "
],
skeleton: [
["humerus", [16, 5.5], [10, 6]],
["radiusulna", [10, 5.7], [4.8, 4.8]],
["radiusulna", [10, 6.3], [4.8, 5.3]],
["carpals", [4.8, 5], [4.2, 5]],
["metacarpals", [4.2, 5], [2.7, 5]],
["foreDigits", [2.7, 5], [0.7, 2.5]],
["foreDigits", [2.7, 5], [0.2, 7.3]],
["foreDigits", [2.7, 5], [1.2, 10]],
["femur", [18, 12], [18, 15.6]],
["tibiafibula", [17.6, 15.6], [17.6, 17.1]],
["tibiafibula", [18.4, 15.6], [18.4, 17.1]],
["tarsals", [18, 17.1], [18, 17.5]],
["metatarsals", [18, 17.5], [18, 18]],
["hindDigits", [18, 18], [19.5, 18]],
["hindDigits", [18, 18], [17, 18]]
]
},
{
id: "bat",
name: "Bat",
latin: "Pteropus",
x: 2.0,
scale: 0.12,
accent: "#75d6c7",
grid: [
" ",
" HHHHH ",
" HHHHH ",
" HHH ",
" NNN ",
"WWWWWWWWWWWWWNNNNNNNNNNNNWWWWW",
" WWWWWWWWWWWWNNNNNNNNNNNNNWWW ",
" WWWWWWWWWWNNNNNNNNNNNNNWW ",
" WWWWWWWWWNNNNNNNNNNNNNWW ",
" WWWWWWWNNNNNNNNNNNNN ",
" WWWNNNNNNNNNNNNNNN ",
" NNNNNNNNNNNNNNNN ",
" NNNNNNNNNNNNNN ",
" NNNNNNNNNNNN ",
" LLL LLLLLLL ",
" LLL LLLLLLL ",
" LLL LLLLLLL ",
" LL LLLLLL ",
" L LLLL ",
" LLL "
],
skeleton: [
["humerus", [17, 5], [11, 7]],
["radiusulna", [11, 6.7], [4.1, 5.8]],
["radiusulna", [11, 7.3], [4.1, 6.3]],
["carpals", [4.1, 6], [3.4, 6]],
["metacarpals", [3.4, 6], [2.3, 6]],
["foreDigits", [2.3, 6], [0.1, 2.3]],
["foreDigits", [2.3, 6], [0, 8.7]],
["foreDigits", [2.3, 6], [1, 11]],
["femur", [17, 13], [17, 17.1]],
["tibiafibula", [16.6, 17.1], [16.6, 19]],
["tibiafibula", [17.4, 17.1], [17.4, 19]],
["tarsals", [17, 19], [17, 19.5]],
["metatarsals", [17, 19.5], [17, 20]],
["hindDigits", [17, 20], [18.4, 20]],
["hindDigits", [17, 20], [16.2, 20]]
]
},
{
id: "human",
name: "Human",
latin: "Homo sapiens",
x: 5.8,
scale: 0.14,
accent: "#e7b779",
grid: [
" HHHHH ",
" HHHHHHH ",
" HHHHHHH ",
" HHHHH ",
" TTTTTT ",
" TTTTTTTT ",
" TTTTTTTT ",
" TTTTTTTT ",
" TTTTTT ",
" AAATAAAA ",
" AAATAAAA ",
" AAATAAAA ",
" AAATAAAA ",
" AAAAAA ",
" AAAA ",
" TT ",
" LLLL ",
" LLLL ",
" LLLL ",
" LLLL ",
" LLLLLL ",
" LLLLLL ",
" LLLL ",
" LL ",
" LL ",
" LL ",
" LLLL "
],
skeleton: [
["humerus", [8, 8], [8, 12]],
["radiusulna", [7.6, 12], [7.6, 15]],
["radiusulna", [8.4, 12], [8.4, 15]],
["carpals", [8, 15], [8, 16]],
["metacarpals", [8, 16], [8, 17.4]],
["foreDigits", [8, 17.4], [8, 19.8]],
["foreDigits", [8, 17.4], [9.2, 19.3]],
["femur", [7, 16], [7, 20.4]],
["tibiafibula", [6.6, 20.4], [6.6, 24.1]],
["tibiafibula", [7.4, 20.4], [7.4, 24.1]],
["tarsals", [7, 24.1], [7, 25]],
["metatarsals", [7, 25], [7, 26]],
["hindDigits", [7, 26], [8.8, 26.4]],
["hindDigits", [7, 26], [6.2, 26.4]]
]
}
];
// ------------------------------------------------------------
// Homology definitions and explanatory copy
// ------------------------------------------------------------
const parts = {
humerus: {
limb: "fore",
order: 1,
title: "Humerus",
note:
"The upper-arm element is inherited across these tetrapods, but its proportions, attachment sites and mechanical loads are very different."
},
radiusulna: {
limb: "fore",
order: 2,
title: "Radius / ulna",
note:
"The paired forearm bones become distinct levers for manipulation, flight-stroke control or the rigid framework of a bird wing. Bat and bird proportions are especially modified."
},
carpals: {
limb: "fore",
order: 3,
title: "Carpals",
note:
"Wrist elements are rearranged and differently proportioned. Their arrangement changes the directions and range of motion available to the hand or wing."
},
metacarpals: {
limb: "fore",
order: 4,
title: "Metacarpals",
note:
"Palm and wing metacarpals share ancestry while trading grasping surfaces, support and span. Corresponding bones should not be read as exact functional equivalents."
},
foreDigits: {
limb: "fore",
order: 5,
title: "Digits",
note:
"Digital identities persist even when digits become elongated, reduced, fused or repurposed. Bat wing rays and human fingers are homologous, not mechanically identical."
},
femur: {
limb: "hind",
order: 1,
title: "Femur",
note:
"The thigh bone is shared, while its orientation, leverage and loading differ among bipedal, quadrupedal, climbing and flight-adapted lineages."
},
tibiafibula: {
limb: "hind",
order: 2,
title: "Tibia / fibula",
note:
"These lower-leg bones retain a shared developmental origin. Their relative size, contribution to support and visible surface anatomy can vary substantially."
},
tarsals: {
limb: "hind",
order: 3,
title: "Tarsals",
note:
"Ankle elements are homologous across tetrapods, but their arrangement and fusion patterns produce very different feet and landing mechanics."
},
metatarsals: {
limb: "hind",
order: 4,
title: "Metatarsals",
note:
"Foot and palm elements share deep ancestry. Differences in length and fusion reflect different balances between speed, support, grip and perching."
},
hindDigits: {
limb: "hind",
order: 5,
title: "Digits",
note:
"Hindlimb digits remain recognizable in modified form. Their orientations and loads differ, so a homologous match does not imply the same movement."
}
};
const limbLabels = {
fore: "Forelimb",
hind: "Hindlimb"
};
// ------------------------------------------------------------
// Voxel models and detached bone overlays
// ------------------------------------------------------------
const boneGeometry = new THREE.BoxGeometry(1, 1, 1);
const yAxis = new THREE.Vector3(0, 1, 0);
const neutralBoneMaterial = new THREE.MeshStandardMaterial({
color: 0xd9e2de,
roughness: 0.58,
metalness: 0.04,
emissive: 0x081116,
emissiveIntensity: 0.4
});
const selectedBoneMaterial = new THREE.MeshStandardMaterial({
color: 0x79f0d8,
roughness: 0.35,
metalness: 0.08,
emissive: 0x1f9f89,
emissiveIntensity: 0.72
});
const models = [];
const bodyMeshes = [];
const boneMeshes = [];
const pickMeshes = [];
function gridPoint(model, coordinate) {
const [column, row] = coordinate;
return new THREE.Vector3(
(column - model.width / 2 + 0.5) * model.scale,
(model.height - row - 0.5) * model.scale,
0
);
}
function makeVoxelBody(model) {
const group = new THREE.Group();
group.position.x = model.x;
const cells = [];
model.grid.forEach((row, y) => {
for (let x = 0; x < model.width; x += 1) {
const character = row[x];
if (character && character !== " ") {
cells.push({ x, y, character });
}
}
});
const geometry = new THREE.BoxGeometry(
model.scale * 0.9,
model.scale * 0.9,
model.scale * 0.7
);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.87,
metalness: 0.02,
transparent: true,
opacity: 1
});
const mesh = new THREE.InstancedMesh(geometry, material, cells.length);
const dummy = new THREE.Object3D();
const base = new THREE.Color("#405767");
const dark = new THREE.Color("#263b49");
const accent = new THREE.Color(model.accent);
const wing = base.clone().lerp(accent, 0.2);
cells.forEach((cell, index) => {
dummy.position.set(
(cell.x - model.width / 2 + 0.5) * model.scale,
(model.height - cell.y - 0.5) * model.scale,
0
);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
let color = base;
if (cell.character === "H") color = accent;
if (cell.character === "L" || cell.character === "A" || cell.character === "F") {
color = dark;
}
if (cell.character === "W") color = wing;
if (cell.character === "T") color = base.clone().lerp(accent, 0.07);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.instanceColor.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.species = model.id;
group.add(mesh);
const plinthWidth =
model.id === "human" ? 3.1 : model.id === "bird" ? 3.8 : 4.05;
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(plinthWidth, 0.09, 1.55),
new THREE.MeshStandardMaterial({
color: 0x0c1a21,
roughness: 0.95,
metalness: 0.02
})
);
plinth.position.y = -0.09;
plinth.receiveShadow = true;
group.add(plinth);
const edgeMaterial = new THREE.LineBasicMaterial({
color: model.accent,
transparent: true,
opacity: 0.36
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(plinth.geometry),
edgeMaterial
);
edges.position.copy(plinth.position);
group.add(edges);
const accentBar = new THREE.Mesh(
new THREE.BoxGeometry(plinthWidth * 0.76, 0.012, 0.025),
new THREE.MeshBasicMaterial({
color: model.accent,
transparent: true,
opacity: 0.72
})
);
accentBar.position.set(0, -0.037, 0.79);
group.add(accentBar);
model.group = group;
model.bodyMesh = mesh;
model.bodyMaterial = material;
model.plinthEdge = edgeMaterial;
model.accentBar = accentBar;
bodyMeshes.push(mesh);
pickMeshes.push(mesh);
}
function makeSkeleton(model) {
const group = new THREE.Group();
model.boneGroup = group;
model.group.add(group);
model.partMeshes = {};
model.partJoints = {};
model.partCenters = {};
const segmentThickness = model.scale * 0.48;
const digitThickness = model.scale * 0.36;
for (const [part, start, end] of model.skeleton) {
if (!model.partMeshes[part]) {
model.partMeshes[part] = [];
model.partJoints[part] = [];
}
const a = gridPoint(model, start);
const b = gridPoint(model, end);
const direction = b.clone().sub(a);
const length = direction.length();
const mesh = new THREE.Mesh(
boneGeometry,
neutralBoneMaterial
);
const thickness =
part === "foreDigits" || part === "hindDigits"
? digitThickness
: segmentThickness;
mesh.scale.set(thickness, length, thickness);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
mesh.castShadow = true;
mesh.userData.part = part;
mesh.userData.species = model.id;
group.add(mesh);
model.partMeshes[part].push(mesh);
boneMeshes.push(mesh);
pickMeshes.push(mesh);
for (const point of [a, b]) {
const joint = new THREE.Mesh(
boneGeometry,
neutralBoneMaterial
);
joint.scale.setScalar(thickness * 1.42);
joint.position.copy(point);
joint.castShadow = true;
joint.userData.part = part;
joint.userData.species = model.id;
group.add(joint);
model.partJoints[part].push(joint);
boneMeshes.push(joint);
pickMeshes.push(joint);
}
}
for (const part of Object.keys(model.partMeshes)) {
const center = new THREE.Vector3();
for (const mesh of model.partMeshes[part]) {
center.add(mesh.position);
}
center.multiplyScalar(1 / model.partMeshes[part].length);
model.partCenters[part] = center;
}
}
for (const data of speciesData) {
const model = {
...data,
width: Math.max(...data.grid.map((row) => row.length)),
height: data.grid.length
};
makeVoxelBody(model);
makeSkeleton(model);
scene.add(model.group);
models.push(model);
const label = document.createElement("button");
label.type = "button";
label.className = "animal-label";
label.style.setProperty("--species-color", model.accent);
label.innerHTML = `
<i></i>
<strong>${model.name}</strong>
<span>${model.latin}</span>
`;
label.addEventListener("click", () => selectSpecies(model.id));
labelsHost.appendChild(label);
model.label = label;
}
// ------------------------------------------------------------
// Homology rail: matching structures connect to a shared rail.
// This avoids implying a linear evolutionary sequence.
// ------------------------------------------------------------
const connectorGroup = new THREE.Group();
scene.add(connectorGroup);
const connectorLineMaterial = new THREE.LineDashedMaterial({
color: 0x6ee7d0,
transparent: true,
opacity: 0.66,
dashSize: 0.12,
gapSize: 0.08,
depthTest: false,
depthWrite: false
});
const connectorNodeMaterial = new THREE.MeshBasicMaterial({
color: 0x6ee7d0,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false
});
let railLabelPosition = null;
function clearConnectors() {
connectorGroup.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
connectorGroup.clear();
railLabelPosition = null;
railLabel.style.display = "none";
}
function worldPartCenter(model, part) {
const center = model.partCenters[part].clone();
model.boneGroup.updateMatrixWorld(true);
model.group.updateMatrixWorld(true);
return model.boneGroup.localToWorld(center);
}
function rebuildConnectors() {
clearConnectors();
if (!showBones || !selectedPart) return;
const centers = models
.map((model) => worldPartCenter(model, selectedPart))
.sort((a, b) => a.x - b.x);
const railY = Math.max(...centers.map((center) => center.y)) + 0.72;
const railZ = 1.35;
const minX = Math.min(...centers.map((center) => center.x));
const maxX = Math.max(...centers.map((center) => center.x));
const railGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(minX - 0.2, railY, railZ),
new THREE.Vector3(maxX + 0.2, railY, railZ)
]);
const rail = new THREE.Line(railGeometry, connectorLineMaterial);
rail.computeLineDistances();
rail.renderOrder = 20;
connectorGroup.add(rail);
for (const center of centers) {
const railPoint = new THREE.Vector3(center.x, railY, railZ);
const control = center.clone().lerp(railPoint, 0.5);
control.y = Math.max(center.y, railY) + 0.14;
control.z = 1.0;
const curve = new THREE.QuadraticBezierCurve3(
center,
control,
railPoint
);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(28)
);
const line = new THREE.Line(geometry, connectorLineMaterial);
line.computeLineDistances();
line.renderOrder = 20;
connectorGroup.add(line);
const structureNode = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.09, 0.09),
connectorNodeMaterial
);
structureNode.position.copy(center);
structureNode.renderOrder = 21;
connectorGroup.add(structureNode);
const railNode = new THREE.Mesh(
new THREE.BoxGeometry(0.07, 0.07, 0.07),
connectorNodeMaterial
);
railNode.position.copy(railPoint);
railNode.renderOrder = 21;
connectorGroup.add(railNode);
}
railLabelPosition = new THREE.Vector3(
maxX + 0.12,
railY,
railZ
);
}
// ------------------------------------------------------------
// UI state and interaction
// ------------------------------------------------------------
let selectedPart = "humerus";
let selectedLimb = "fore";
let selectedSpecies = "bat";
let showBones = true;
let detachBones = true;
let separation = 0.28;
function updateBoneAppearance() {
for (const mesh of boneMeshes) {
mesh.material =
mesh.userData.part === selectedPart
? selectedBoneMaterial
: neutralBoneMaterial;
}
}
function updateSeparation() {
const effective = detachBones ? separation : 0;
for (const model of models) {
model.boneGroup.position.z = effective * 0.9;
model.boneGroup.visible = showBones;
model.bodyMaterial.opacity = 1 - effective * 0.62;
model.accentBar.material.opacity = 0.5 + effective * 0.5;
}
$("#separation").disabled = !detachBones;
$("#separationValue").textContent = `${Math.round(separation * 100)}%`;
rebuildConnectors();
}
function selectSpecies(id) {
selectedSpecies = id;
const model = models.find((item) => item.id === id);
for (const item of models) {
const active = item.id === id;
item.label.classList.toggle("active", active);
item.plinthEdge.opacity = active ? 0.9 : 0.3;
item.plinthEdge.color.set(
active ? item.accent : new THREE.Color(item.accent).multiplyScalar(0.5)
);
}
$$(".taxon-choice, .tree-species").forEach((element) => {
element.classList.toggle(
"active",
element.dataset.species === selectedSpecies
);
});
$("#focusReadout").textContent = model.name;
}
function selectPart(part) {
selectedPart = part;
const definition = parts[part];
if (definition.limb !== selectedLimb) {
selectedLimb = definition.limb;
renderPartButtons();
}
updateBoneAppearance();
$$(".part-button").forEach((button) => {
button.classList.toggle("active", button.dataset.part === part);
});
$("#matchCategory").textContent =
`${limbLabels[definition.limb]} / ${String(definition.order).padStart(2, "0")}`;
$("#matchTitle").textContent = definition.title;
$("#matchNote").textContent = definition.note;
$("#matchCount").textContent = `${models.length} taxa matched`;
$("#matchReadout").textContent = `${models.length} / ${models.length}`;
rebuildConnectors();
}
function renderPartButtons() {
const grid = $("#partGrid");
grid.innerHTML = "";
const visibleParts = Object.entries(parts)
.filter(([, definition]) => definition.limb === selectedLimb)
.sort(([, a], [, b]) => a.order - b.order);
for (const [id, definition] of visibleParts) {
const button = document.createElement("button");
button.type = "button";
button.className = "part-button";
button.dataset.part = id;
button.innerHTML = `
<span>${String(definition.order).padStart(2, "0")}</span>
<strong>${definition.title}</strong>
`;
button.addEventListener("click", () => selectPart(id));
grid.appendChild(button);
}
$$(".limb-tab").forEach((tab) => {
tab.classList.toggle("active", tab.dataset.limb === selectedLimb);
});
}
$$(".limb-tab").forEach((tab) => {
tab.addEventListener("click", () => {
selectedLimb = tab.dataset.limb;
renderPartButtons();
const firstPart = Object.entries(parts).find(
([, definition]) => definition.limb === selectedLimb
)[0];
selectPart(firstPart);
});
});
$$(".taxon-choice, .tree-species").forEach((element) => {
element.addEventListener("click", () => selectSpecies(element.dataset.species));
});
$("#bonesToggle").addEventListener("change", (event) => {
showBones = event.target.checked;
updateSeparation();
});
$("#detachToggle").addEventListener("change", (event) => {
detachBones = event.target.checked;
updateSeparation();
});
$("#separation").addEventListener("input", (event) => {
separation = Number(event.target.value) / 100;
updateSeparation();
});
$("#resetView").addEventListener("click", () => {
orbit.theta = 0.025;
orbit.phi = 1.2;
orbit.userAdjusted = false;
resize();
});
// ------------------------------------------------------------
// Custom orbit / zoom / picking controls
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
let downPointerX = 0;
let downPointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
downPointerX = event.clientX;
downPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (
Math.abs(event.clientX - downPointerX) +
Math.abs(event.clientY - downPointerY) >
5
) {
pointerMoved = true;
}
orbit.theta -= dx * 0.006;
orbit.phi -= dy * 0.005;
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.52, 1.46);
orbit.userAdjusted = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
if (!pointerMoved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const boneHits = raycaster.intersectObjects(boneMeshes, false);
if (boneHits.length) {
selectPart(boneHits[0].object.userData.part);
return;
}
const bodyHits = raycaster.intersectObjects(bodyMeshes, false);
if (bodyHits.length) {
selectSpecies(bodyHits[0].object.userData.species);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius *= Math.exp(event.deltaY * 0.001);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 10, 32);
orbit.userAdjusted = true;
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.theta = 0.025;
orbit.phi = 1.2;
orbit.userAdjusted = false;
resize();
});
// ------------------------------------------------------------
// Responsive sizing and screen-space labels
// ------------------------------------------------------------
let viewWidth = 1;
let viewHeight = 1;
function resize() {
const rect = canvasHost.getBoundingClientRect();
viewWidth = Math.max(1, rect.width);
viewHeight = Math.max(1, rect.height);
renderer.setSize(viewWidth, viewHeight, false);
camera.aspect = viewWidth / viewHeight;
camera.updateProjectionMatrix();
if (!orbit.userAdjusted) {
orbit.radius = Math.max(16.8, 24 / camera.aspect);
}
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(canvasHost);
resize();
function projectToScreen(position) {
const projected = position.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * viewWidth,
y: (-projected.y * 0.5 + 0.5) * viewHeight
};
}
function updateLabels() {
for (const model of models) {
model.group.updateMatrixWorld(true);
const anchor = new THREE.Vector3(0, -0.2, 0.68);
model.group.localToWorld(anchor);
const screen = projectToScreen(anchor);
model.label.style.left = `${screen.x}px`;
model.label.style.top = `${screen.y}px`;
}
if (railLabelPosition) {
const screen = projectToScreen(railLabelPosition);
railLabel.style.left = `${screen.x}px`;
railLabel.style.top = `${screen.y}px`;
railLabel.style.display = "block";
}
}
// ------------------------------------------------------------
// Initial state and render loop
// ------------------------------------------------------------
renderPartButtons();
selectPart(selectedPart);
selectSpecies(selectedSpecies);
updateSeparation();
renderer.setAnimationLoop(() => {
applyCamera();
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```