Prompt specification
Build or customize the Three.js 3D scene "Forelimb bone correspondence rack" 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: Forelimb bone correspondence rack
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/forelimb-bone-correspondence-rack-x0917
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring homologous anatomical structures. Arrange simplified mammalian forelimbs with corresponding bones colored consistently; label the anatomy schematic and preserve recognizable joint relationships across different overall proportions. Low-poly.
Working Three.js Starter (forelimb-bone-correspondence-rack-x0917):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homologous Mammalian Forelimbs</title>
<style>
:root {
--bg: #09111e;
--panel: #101a2a;
--panel-soft: #162236;
--border: #263750;
--text: #edf3fb;
--muted: #9eacc0;
--accent: #77d4ff;
--scapula: #7186a8;
--humerus: #ff7474;
--radius: #f4bd50;
--ulna: #39b9aa;
--carpals: #a493ff;
--metacarpals: #67ca75;
--phalanges: #f48bda;
}
* {
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;
}
.app-header {
height: 76px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 24px;
border-bottom: 1px solid var(--border);
background:
linear-gradient(90deg, rgba(119, 212, 255, 0.08), transparent 38%),
#0d1726;
position: relative;
z-index: 10;
}
.title-group {
min-width: 0;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(18px, 2vw, 25px);
font-weight: 700;
letter-spacing: -0.025em;
}
.subtitle {
margin: 4px 0 0;
color: var(--muted);
font-size: 12px;
}
.header-badge {
flex: 0 0 auto;
padding: 8px 12px;
border: 1px solid #35506d;
border-radius: 999px;
background: rgba(27, 48, 73, 0.5);
color: #cce8f7;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
main {
height: calc(100vh - 76px);
display: grid;
grid-template-columns: 285px minmax(0, 1fr);
}
.sidebar {
overflow-y: auto;
padding: 20px 18px;
border-right: 1px solid var(--border);
background:
radial-gradient(circle at 0 0, rgba(119, 212, 255, 0.08), transparent 35%),
var(--panel);
z-index: 5;
}
.panel-heading {
margin: 0 0 6px;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel-copy {
margin: 0 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.legend-list {
display: grid;
gap: 6px;
margin-bottom: 20px;
}
.legend-item {
width: 100%;
display: grid;
grid-template-columns: 17px 1fr;
align-items: center;
gap: 10px;
padding: 9px 10px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: var(--text);
text-align: left;
cursor: pointer;
transition:
background 140ms ease,
border-color 140ms ease,
transform 140ms ease;
}
.legend-item:hover,
.legend-item:focus-visible,
.legend-item.active {
border-color: #38516e;
background: var(--panel-soft);
outline: none;
transform: translateX(2px);
}
.swatch {
width: 14px;
height: 14px;
border-radius: 3px;
box-shadow:
inset 0 0 0 1px rgba(255, 255, 255, 0.18),
0 0 12px color-mix(in srgb, currentColor 35%, transparent);
}
.swatch.scapula { background: var(--scapula); color: var(--scapula); }
.swatch.humerus { background: var(--humerus); color: var(--humerus); }
.swatch.radius { background: var(--radius); color: var(--radius); }
.swatch.ulna { background: var(--ulna); color: var(--ulna); }
.swatch.carpals { background: var(--carpals); color: var(--carpals); }
.swatch.metacarpals { background: var(--metacarpals); color: var(--metacarpals); }
.swatch.phalanges { background: var(--phalanges); color: var(--phalanges); }
.legend-name {
display: block;
font-size: 12px;
font-weight: 750;
}
.legend-detail {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.controls {
display: grid;
gap: 10px;
padding-top: 16px;
border-top: 1px solid var(--border);
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
color: #d9e3f0;
font-size: 12px;
}
.control-row input {
width: 16px;
height: 16px;
accent-color: var(--accent);
}
.reset-button {
width: 100%;
padding: 10px 12px;
border: 1px solid #38516e;
border-radius: 8px;
background: #16263b;
color: #e7f4ff;
font-size: 12px;
font-weight: 750;
cursor: pointer;
}
.reset-button:hover {
background: #1c3049;
border-color: #527699;
}
.note-card {
margin-top: 18px;
padding: 13px;
border-left: 3px solid var(--accent);
border-radius: 4px 9px 9px 4px;
background: rgba(119, 212, 255, 0.07);
}
.note-card strong {
display: block;
margin-bottom: 5px;
color: #dff6ff;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.note-card p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #09111e;
}
#canvas-wrap,
#label-layer {
position: absolute;
inset: 0;
}
#canvas-wrap canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#label-layer {
pointer-events: none;
overflow: hidden;
}
.specimen-label {
position: absolute;
min-width: 136px;
max-width: 190px;
padding: 8px 11px;
transform: translate(-50%, -100%);
border: 1px solid rgba(125, 154, 186, 0.32);
border-radius: 9px;
background: rgba(12, 22, 36, 0.82);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(8px);
text-align: center;
transition: opacity 160ms ease;
}
.specimen-label .name {
display: block;
color: #f5f9ff;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.specimen-label .adaptation {
display: block;
margin-top: 3px;
color: #aab8ca;
font-size: 10px;
line-height: 1.3;
}
#label-layer.labels-hidden .specimen-label {
opacity: 0;
}
.hud {
position: absolute;
right: 16px;
top: 16px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid rgba(91, 119, 150, 0.32);
border-radius: 7px;
background: rgba(11, 20, 33, 0.76);
color: #aebbd0;
font-size: 10px;
pointer-events: none;
}
.hud-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
.hint {
position: absolute;
left: 16px;
bottom: 14px;
padding: 7px 10px;
border-radius: 6px;
background: rgba(10, 18, 30, 0.7);
color: #8998ad;
font-size: 10px;
pointer-events: none;
}
.tooltip {
position: absolute;
z-index: 20;
width: 220px;
padding: 11px 12px;
border: 1px solid #3b5677;
border-radius: 9px;
background: rgba(10, 19, 32, 0.96);
box-shadow: 0 15px 35px rgba(0, 0, 0, 0.38);
pointer-events: none;
opacity: 0;
transform: translateY(4px);
transition:
opacity 100ms ease,
transform 100ms ease;
}
.tooltip.visible {
opacity: 1;
transform: translateY(0);
}
.tooltip-title {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 5px;
color: #fff;
font-size: 12px;
font-weight: 800;
}
.tooltip-title span {
width: 9px;
height: 9px;
border-radius: 2px;
}
.tooltip-copy {
color: #aebbd0;
font-size: 11px;
line-height: 1.45;
}
@media (max-width: 860px) {
body {
overflow: auto;
}
.app-header {
height: auto;
min-height: 74px;
padding: 13px 16px;
}
.header-badge {
display: none;
}
main {
height: auto;
display: flex;
flex-direction: column;
}
.sidebar {
overflow: visible;
padding: 12px;
border-right: 0;
border-bottom: 1px solid var(--border);
}
.sidebar > .panel-heading,
.sidebar > .panel-copy,
.note-card {
display: none;
}
.legend-list {
display: flex;
gap: 5px;
overflow-x: auto;
padding-bottom: 4px;
margin-bottom: 10px;
}
.legend-item {
min-width: 128px;
padding: 7px 8px;
}
.legend-detail {
display: none;
}
.controls {
grid-template-columns: auto 145px;
align-items: center;
padding-top: 8px;
}
.stage {
height: 72vh;
min-height: 560px;
}
.hud {
display: none;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="title-group">
<div class="eyebrow">Comparative Anatomy · Schematic 01</div>
<h1>Homologous Mammalian Forelimbs</h1>
<p class="subtitle">
Shared bone architecture transformed by evolution
</p>
</div>
<div class="header-badge">Color = developmental homology</div>
</header>
<main>
<aside class="sidebar">
<h2 class="panel-heading">Anatomy key</h2>
<p class="panel-copy">
Hover a key or a bone to illuminate every corresponding structure
across the four species.
</p>
<div class="legend-list" id="legend-list">
<button class="legend-item" data-type="scapula" type="button">
<span class="swatch scapula"></span>
<span>
<span class="legend-name">Scapula</span>
<span class="legend-detail">Shoulder blade</span>
</span>
</button>
<button class="legend-item" data-type="humerus" type="button">
<span class="swatch humerus"></span>
<span>
<span class="legend-name">Humerus</span>
<span class="legend-detail">Upper arm</span>
</span>
</button>
<button class="legend-item" data-type="radius" type="button">
<span class="swatch radius"></span>
<span>
<span class="legend-name">Radius</span>
<span class="legend-detail">Thumb-side forearm</span>
</span>
</button>
<button class="legend-item" data-type="ulna" type="button">
<span class="swatch ulna"></span>
<span>
<span class="legend-name">Ulna</span>
<span class="legend-detail">Little-finger-side forearm</span>
</span>
</button>
<button class="legend-item" data-type="carpals" type="button">
<span class="swatch carpals"></span>
<span>
<span class="legend-name">Carpals</span>
<span class="legend-detail">Wrist bones</span>
</span>
</button>
<button class="legend-item" data-type="metacarpals" type="button">
<span class="swatch metacarpals"></span>
<span>
<span class="legend-name">Metacarpals</span>
<span class="legend-detail">Palm bones</span>
</span>
</button>
<button class="legend-item" data-type="phalanges" type="button">
<span class="swatch phalanges"></span>
<span>
<span class="legend-name">Phalanges</span>
<span class="legend-detail">Digit bones</span>
</span>
</button>
</div>
<div class="controls">
<label class="control-row" for="labels-toggle">
<span>Show specimen labels</span>
<input id="labels-toggle" type="checkbox" checked>
</label>
<button class="reset-button" id="reset-view" type="button">
Reset camera
</button>
</div>
<div class="note-card">
<strong>Homology, not scale</strong>
<p>
Every limb preserves the same connected sequence: shoulder → elbow →
wrist → palm → digits. Length, width, orientation, and the number of
phalanges vary between species.
</p>
</div>
</aside>
<section class="stage" id="stage" aria-label="Interactive 3D comparative anatomy scene">
<div id="canvas-wrap"></div>
<div id="label-layer"></div>
<div class="hud">
<span class="hud-dot"></span>
<span>Hover a bone to identify it</span>
</div>
<div class="hint">
Drag to orbit · Shift/right-drag to pan · Scroll to zoom · R to reset
</div>
<div class="tooltip" id="tooltip" role="status" aria-live="polite">
<div class="tooltip-title">
<span id="tooltip-swatch"></span>
<span id="tooltip-name"></span>
</div>
<div class="tooltip-copy" id="tooltip-copy"></div>
</div>
</section>
</main>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const canvasWrap = document.getElementById("canvas-wrap");
const labelLayer = document.getElementById("label-layer");
const tooltip = document.getElementById("tooltip");
const tooltipName = document.getElementById("tooltip-name");
const tooltipCopy = document.getElementById("tooltip-copy");
const tooltipSwatch = document.getElementById("tooltip-swatch");
const labelsToggle = document.getElementById("labels-toggle");
const COLORS = {
scapula: 0x7186a8,
humerus: 0xff7474,
radius: 0xf4bd50,
ulna: 0x39b9aa,
carpals: 0xa493ff,
metacarpals: 0x67ca75,
phalanges: 0xf48bda
};
const CSS_COLORS = {
scapula: "#7186a8",
humerus: "#ff7474",
radius: "#f4bd50",
ulna: "#39b9aa",
carpals: "#a493ff",
metacarpals: "#67ca75",
phalanges: "#f48bda"
};
const ANATOMY = {
scapula: {
name: "Scapula",
description: "Shoulder blade. It anchors the upper limb to the trunk."
},
humerus: {
name: "Humerus",
description: "Upper-arm bone, connecting the shoulder joint to the elbow."
},
radius: {
name: "Radius",
description: "Forearm bone on the thumb side, connecting elbow and wrist."
},
ulna: {
name: "Ulna",
description: "Forearm bone on the little-finger side, connecting elbow and wrist."
},
carpals: {
name: "Carpals",
description: "Small wrist bones forming the transition into the palm."
},
metacarpals: {
name: "Metacarpals",
description: "Palm bones. Their relative lengths shape the hand or flipper."
},
phalanges: {
name: "Phalanges",
description: "Digit bones. Their number and elongation differ among species."
}
};
const SPECIES = [
{
name: "Human",
adaptation: "Opposable, generalized hand",
x: -6.25,
elbow: [0.08, -2.05, 0],
wrist: [0.00, -3.48, 0],
metacarpals: [
{ x: -0.50, length: 0.80 },
{ x: -0.26, length: 0.92 },
{ x: 0.00, length: 0.95 },
{ x: 0.26, length: 0.90 },
{ x: 0.50, length: 0.76 }
],
digits: [0.65, 0.82, 0.85, 0.74, 0.59],
segments: 3,
spread: 0.075,
scapula: [0.57, 0.62],
humerusR: 0.135,
forearmR: 0.076,
carpalR: 0.073,
metaR: 0.046,
digitR: 0.029,
jointR: 0.125
},
{
name: "Domestic dog",
adaptation: "Digitigrade limb with compact digits",
x: -2.08,
elbow: [-0.12, -1.60, 0],
wrist: [-0.08, -2.92, 0],
metacarpals: [
{ x: -0.43, length: 0.53 },
{ x: -0.22, length: 0.61 },
{ x: 0.00, length: 0.62 },
{ x: 0.22, length: 0.59 },
{ x: 0.43, length: 0.52 }
],
digits: [0.40, 0.50, 0.54, 0.47, 0.38],
segments: 3,
spread: 0.060,
scapula: [0.66, 0.48],
humerusR: 0.115,
forearmR: 0.064,
carpalR: 0.063,
metaR: 0.039,
digitR: 0.026,
jointR: 0.112
},
{
name: "Fruit bat",
adaptation: "Elongated metacarpals and wing digits",
x: 2.18,
elbow: [0.00, -1.08, 0],
wrist: [0.02, -2.72, 0],
metacarpals: [
{ x: -1.48, length: 1.90 },
{ x: -0.76, length: 2.24 },
{ x: 0.00, length: 2.44 },
{ x: 0.76, length: 2.16 },
{ x: 1.48, length: 1.76 }
],
digits: [0.84, 1.02, 1.14, 1.00, 0.78],
segments: 3,
spread: 0.035,
scapula: [0.42, 0.36],
humerusR: 0.087,
forearmR: 0.050,
carpalR: 0.052,
metaR: 0.032,
digitR: 0.021,
jointR: 0.090
},
{
name: "Sperm whale",
adaptation: "Broad flipper with extra phalanges",
x: 6.25,
elbow: [0.13, -0.98, 0],
wrist: [0.25, -1.78, 0],
metacarpals: [
{ x: -0.34, length: 0.30 },
{ x: -0.17, length: 0.38 },
{ x: 0.00, length: 0.42 },
{ x: 0.17, length: 0.36 },
{ x: 0.34, length: 0.28 }
],
digits: [0.60, 0.68, 0.74, 0.66, 0.56],
segments: 4,
spread: 0.018,
scapula: [0.76, 0.43],
humerusR: 0.163,
forearmR: 0.106,
carpalR: 0.090,
metaR: 0.058,
digitR: 0.041,
jointR: 0.145
}
];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09111e);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
canvasWrap.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -1.45, 0);
let cameraTheta = 0;
let cameraPhi = 0;
let cameraZoom = 1;
scene.add(new THREE.HemisphereLight(0xbad9ff, 0x172033, 1.65));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.35);
keyLight.position.set(5, 8, 10);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x65baff, 1.2);
rimLight.position.set(-7, 3, -5);
scene.add(rimLight);
const warmLight = new THREE.DirectionalLight(0xffc27a, 0.65);
warmLight.position.set(4, -5, 7);
scene.add(warmLight);
const grid = new THREE.GridHelper(18, 18, 0x38506d, 0x1c2b40);
grid.position.y = -6.55;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
const separatorMaterial = new THREE.LineBasicMaterial({
color: 0x263750,
transparent: true,
opacity: 0.65
});
[-4.17, 0.05, 4.22].forEach((x) => {
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, -6.55, -0.65),
new THREE.Vector3(x, 1.35, -0.65)
]);
scene.add(new THREE.Line(geometry, separatorMaterial));
});
const materials = {};
const boneMeshes = [];
const specimenLabels = [];
Object.entries(COLORS).forEach(([type, color]) => {
materials[type] = new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.04,
flatShading: true,
emissive: 0x000000,
emissiveIntensity: 0
});
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xd5deeb,
roughness: 0.58,
metalness: 0.08,
flatShading: true
});
const UP = new THREE.Vector3(0, 1, 0);
function vector(values) {
return new THREE.Vector3(values[0], values[1], values[2]);
}
function addAnatomyMesh(group, geometry, type, position = null) {
const mesh = new THREE.Mesh(geometry, materials[type]);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.type = type;
if (position) {
mesh.position.copy(position);
}
group.add(mesh);
boneMeshes.push(mesh);
return mesh;
}
function addShaft(group, a, b, radius, type, knobs = false) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
if (length < 0.001) {
return null;
}
const geometry = new THREE.CylinderGeometry(
radius * 0.82,
radius,
length,
6,
1,
false
);
const mesh = addAnatomyMesh(group, geometry, type);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(UP, direction.normalize());
if (knobs) {
addKnob(group, a, radius * 1.22, type);
addKnob(group, b, radius * 1.18, type);
}
return mesh;
}
function addKnob(group, position, radius, type) {
const geometry = new THREE.IcosahedronGeometry(radius, 0);
return addAnatomyMesh(group, geometry, type, position);
}
function addJoint(group, position, radius) {
const geometry = new THREE.IcosahedronGeometry(radius, 1);
const joint = new THREE.Mesh(geometry, jointMaterial);
joint.position.copy(position);
joint.castShadow = true;
group.add(joint);
return joint;
}
function addScapula(group, config) {
const [width, height] = config.scapula;
const shape = new THREE.Shape();
shape.moveTo(-width * 0.40, height * 0.48);
shape.lineTo(width * 0.10, height);
shape.lineTo(width * 0.72, height * 0.47);
shape.lineTo(width * 0.42, height * 0.03);
shape.lineTo(width * 0.07, -height * 0.13);
shape.lineTo(-width * 0.12, height * 0.04);
shape.lineTo(-width * 0.37, height * 0.17);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.10,
bevelEnabled: false,
curveSegments: 1,
steps: 1
});
geometry.translate(0, 0, -0.25);
const mesh = addAnatomyMesh(group, geometry, "scapula");
mesh.castShadow = true;
addShaft(
group,
new THREE.Vector3(0, 0, -0.12),
new THREE.Vector3(-width * 0.08, height * 0.10, -0.13),
config.humerusR * 0.42,
"scapula"
);
}
function addCarpals(group, wrist, config) {
const offsets = [
[-0.13, 0.065, -0.035],
[0.00, 0.070, 0.035],
[0.13, 0.060, -0.025],
[-0.10, -0.065, 0.025],
[0.02, -0.075, -0.035],
[0.14, -0.060, 0.030]
];
offsets.forEach(([x, y, z]) => {
const position = wrist.clone().add(new THREE.Vector3(x, y, z));
const geometry = new THREE.IcosahedronGeometry(config.carpalR, 0);
addAnatomyMesh(group, geometry, "carpals", position);
});
}
function buildSpecimen(config) {
const group = new THREE.Group();
group.position.x = config.x;
scene.add(group);
const shoulder = new THREE.Vector3(0, 0, 0);
const elbow = vector(config.elbow);
const wrist = vector(config.wrist);
addScapula(group, config);
addJoint(group, shoulder, config.jointR);
addShaft(
group,
shoulder,
elbow,
config.humerusR,
"humerus",
true
);
addJoint(group, elbow, config.jointR * 0.94);
const radiusProximal = elbow.clone().add(
new THREE.Vector3(0.09, 0, 0.035)
);
const radiusDistal = wrist.clone().add(
new THREE.Vector3(0.08, 0, 0.035)
);
addShaft(
group,
radiusProximal,
radiusDistal,
config.forearmR,
"radius",
true
);
const ulnaProximal = elbow.clone().add(
new THREE.Vector3(-0.10, 0, -0.035)
);
const ulnaDistal = wrist.clone().add(
new THREE.Vector3(-0.075, 0, -0.035)
);
const ulnaMiddle = ulnaProximal.clone().lerp(ulnaDistal, 0.5);
ulnaMiddle.x -= 0.035;
ulnaMiddle.z -= 0.025;
addShaft(
group,
ulnaProximal,
ulnaMiddle,
config.forearmR * 0.95,
"ulna"
);
addShaft(
group,
ulnaMiddle,
ulnaDistal,
config.forearmR * 0.88,
"ulna"
);
addJoint(group, wrist, config.jointR * 0.82);
addCarpals(group, wrist, config);
const zOffsets = [-0.085, -0.042, 0, 0.042, 0.085];
const segmentFractions = config.segments === 4
? [0.28, 0.25, 0.23, 0.24]
: [0.42, 0.32, 0.26];
config.metacarpals.forEach((ray, index) => {
const z = zOffsets[index];
const metacarpalStart = new THREE.Vector3(
wrist.x + ray.x * 0.10,
wrist.y - 0.12,
wrist.z + z * 0.35
);
const metacarpalEnd = new THREE.Vector3(
ray.x,
wrist.y - ray.length,
wrist.z + z
);
addShaft(
group,
metacarpalStart,
metacarpalEnd,
config.metaR,
"metacarpals",
true
);
const digitLength = config.digits[index];
const directionSign = Math.sign(ray.x) || (index === 0 ? -1 : 1);
const middleFactor = index === 2 ? 0.28 : 1;
const outward = directionSign * config.spread * middleFactor;
const direction = new THREE.Vector3(outward, -1, 0).normalize();
let current = metacarpalEnd.clone();
segmentFractions.forEach((fraction) => {
const next = current.clone().addScaledVector(
direction,
digitLength * fraction
);
addShaft(
group,
current,
next,
config.digitR,
"phalanges"
);
current = next;
});
});
const label = document.createElement("div");
label.className = "specimen-label";
label.innerHTML = `
<span class="name">${config.name}</span>
<span class="adaptation">${config.adaptation}</span>
`;
labelLayer.appendChild(label);
specimenLabels.push({
element: label,
position: new THREE.Vector3(config.x, 1.03, 0)
});
}
SPECIES.forEach(buildSpecimen);
function resize() {
const width = Math.max(stage.clientWidth, 1);
const height = Math.max(stage.clientHeight, 1);
const aspect = width / height;
const viewHeight = Math.max(9.8, 16.4 / aspect);
camera.left = -viewHeight * aspect / 2;
camera.right = viewHeight * aspect / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
function updateCamera() {
const radius = 20;
const horizontalRadius = Math.cos(cameraPhi) * radius;
camera.position.set(
cameraTarget.x + Math.sin(cameraTheta) * horizontalRadius,
cameraTarget.y + Math.sin(cameraPhi) * radius,
cameraTarget.z + Math.cos(cameraTheta) * horizontalRadius
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraTheta = 0;
cameraPhi = 0;
cameraZoom = 1;
cameraTarget.set(0, -1.45, 0);
updateCamera();
resize();
}
function updateLabels() {
const width = stage.clientWidth;
const height = stage.clientHeight;
specimenLabels.forEach(({ element, position }) => {
const projected = position.clone().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;
if (!visible) {
element.style.display = "none";
return;
}
element.style.display = "";
element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
let pinnedType = null;
let hoveredType = null;
function setActiveType(type) {
const active = type || null;
Object.entries(materials).forEach(([key, material]) => {
material.emissive.setHex(active === key ? 0xffffff : 0x000000);
material.emissiveIntensity = active === key ? 0.19 : 0;
});
document.querySelectorAll(".legend-item").forEach((item) => {
const selected = item.dataset.type === active;
item.classList.toggle("active", selected);
item.setAttribute("aria-pressed", selected ? "true" : "false");
});
}
function refreshActiveType() {
setActiveType(hoveredType || pinnedType);
}
document.querySelectorAll(".legend-item").forEach((item) => {
const type = item.dataset.type;
item.addEventListener("mouseenter", () => {
hoveredType = type;
refreshActiveType();
});
item.addEventListener("mouseleave", () => {
hoveredType = null;
refreshActiveType();
});
item.addEventListener("focus", () => {
hoveredType = type;
refreshActiveType();
});
item.addEventListener("blur", () => {
hoveredType = null;
refreshActiveType();
});
item.addEventListener("click", () => {
pinnedType = pinnedType === type ? null : type;
hoveredType = null;
refreshActiveType();
});
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function pointerToNDC(event) {
const rect = renderer.domElement.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
pointer.x = (x / rect.width) * 2 - 1;
pointer.y = -(y / rect.height) * 2 + 1;
return { x, y, rect };
}
function hitTest(event) {
pointerToNDC(event);
raycaster.setFromCamera(pointer, camera);
return raycaster.intersectObjects(boneMeshes, false)[0] || null;
}
function showTooltip(type, event) {
const anatomy = ANATOMY[type];
const rect = stage.getBoundingClientRect();
const localX = event.clientX - rect.left;
const localY = event.clientY - rect.top;
tooltipName.textContent = anatomy.name;
tooltipCopy.textContent = anatomy.description;
tooltipSwatch.style.background = CSS_COLORS[type];
tooltip.style.left = `${Math.max(8, Math.min(localX + 15, rect.width - 232))}px`;
tooltip.style.top = `${Math.max(8, Math.min(localY + 15, rect.height - 112))}px`;
tooltip.classList.add("visible");
}
function hideTooltip() {
tooltip.classList.remove("visible");
}
let pointerState = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointerState = {
id: event.pointerId,
startX: event.clientX,
startY: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
button: event.button,
moved: false
};
hideTooltip();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerState && pointerState.id === event.pointerId) {
const dx = event.clientX - pointerState.lastX;
const dy = event.clientY - pointerState.lastY;
const totalDistance = Math.hypot(
event.clientX - pointerState.startX,
event.clientY - pointerState.startY
);
if (totalDistance > 3) {
pointerState.moved = true;
}
if (pointerState.moved) {
if (event.shiftKey || pointerState.button === 2) {
const scale = 0.012 / cameraZoom;
cameraTarget.x -= dx * scale * Math.cos(cameraTheta);
cameraTarget.z += dx * scale * Math.sin(cameraTheta);
cameraTarget.y += dy * scale;
} else {
cameraTheta -= dx * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi + dy * 0.006,
-0.72,
0.72
);
}
updateCamera();
}
pointerState.lastX = event.clientX;
pointerState.lastY = event.clientY;
return;
}
const hit = hitTest(event);
if (hit) {
const type = hit.object.userData.type;
hoveredType = type;
refreshActiveType();
showTooltip(type, event);
renderer.domElement.style.cursor = "pointer";
} else {
hoveredType = null;
refreshActiveType();
hideTooltip();
renderer.domElement.style.cursor = "grab";
}
});
function endPointer(event) {
if (pointerState && pointerState.id === event.pointerId) {
if (!pointerState.moved && event.button === 0) {
const hit = hitTest(event);
if (hit) {
pinnedType = hit.object.userData.type;
hoveredType = null;
refreshActiveType();
}
}
pointerState = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("pointerleave", () => {
hoveredType = null;
refreshActiveType();
hideTooltip();
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.25
);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset-view").addEventListener("click", resetCamera);
labelsToggle.addEventListener("change", () => {
labelLayer.classList.toggle("labels-hidden", !labelsToggle.checked);
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
if (event.key.toLowerCase() === "l") {
labelsToggle.checked = !labelsToggle.checked;
labelsToggle.dispatchEvent(new Event("change"));
}
});
window.addEventListener("resize", resize);
resetCamera();
function animate() {
renderer.render(scene, camera);
updateLabels();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```