Prompt specification
Build or customize the Three.js 3D scene "Inspect uncertainty in a historical expansion model" 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: Inspect uncertainty in a historical expansion model
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/inspect-uncertainty-in-a-historical-expansion-model-x2576
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows historical Bantu-language expansion. Let users toggle evidence layers and alternative route hypotheses. Keep uncertain boundaries translucent and avoid presenting a single sweeping migration arrow as a complete explanation. Low-poly.
Working Three.js Starter (inspect-uncertainty-in-a-historical-expansion-model-x2576):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bantu-Language Expansions — A Contested Map</title>
<style>
:root {
--ink: #eaf1f2;
--muted: #9eb0b4;
--panel: rgba(12, 25, 31, 0.88);
--panel-edge: rgba(177, 210, 207, 0.18);
--accent: #79c5bd;
--accent-warm: #d6a65d;
--danger: #df8f7c;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09171e;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button, input { font: inherit; }
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene.dragging { cursor: grabbing; }
#labels {
position: fixed;
inset: 0;
pointer-events: none;
overflow: hidden;
z-index: 2;
}
.map-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
white-space: nowrap;
padding: 4px 7px;
border-radius: 4px;
color: rgba(236, 244, 242, 0.9);
background: rgba(8, 21, 27, 0.58);
border: 1px solid rgba(210, 232, 226, 0.12);
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.16);
font-size: 11px;
letter-spacing: 0.035em;
text-shadow: 0 1px 2px #000;
backdrop-filter: blur(3px);
}
.map-label.geo {
color: rgba(221, 232, 231, 0.66);
background: transparent;
border-color: transparent;
text-transform: uppercase;
font-size: 10px;
letter-spacing: 0.18em;
}
.map-label.route {
font-size: 10px;
border-left: 3px solid currentColor;
}
.map-label.genetic {
color: #d7a4c7;
border-color: rgba(215, 164, 199, 0.3);
}
.map-label.climate {
color: #c8bf7a;
border-color: rgba(200, 191, 122, 0.3);
}
.topbar {
position: fixed;
z-index: 10;
left: 18px;
right: 18px;
top: 15px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
}
.brand {
pointer-events: auto;
max-width: min(760px, calc(100vw - 300px));
padding: 14px 17px 13px;
border: 1px solid var(--panel-edge);
border-radius: 12px;
background: linear-gradient(135deg, rgba(10, 24, 30, 0.94),
rgba(16, 38, 42, 0.78));
box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(12px);
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 4px 0 2px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(23px, 3vw, 36px);
font-weight: 500;
letter-spacing: -0.025em;
line-height: 1.05;
}
.subtitle {
margin: 6px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.4;
}
.top-actions {
display: flex;
gap: 8px;
pointer-events: auto;
}
.button {
border: 1px solid var(--panel-edge);
border-radius: 8px;
padding: 9px 12px;
color: var(--ink);
background: rgba(10, 24, 30, 0.88);
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
backdrop-filter: blur(10px);
}
.button:hover {
background: rgba(28, 55, 59, 0.94);
border-color: rgba(177, 210, 207, 0.38);
}
.button:active { transform: translateY(1px); }
.button.primary {
color: #082027;
background: var(--accent);
border-color: transparent;
font-weight: 700;
}
.panel {
position: fixed;
z-index: 10;
top: 111px;
width: 282px;
max-height: calc(100vh - 132px);
overflow: auto;
padding: 15px;
border: 1px solid var(--panel-edge);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(13px);
scrollbar-width: thin;
scrollbar-color: #36565b transparent;
}
#evidencePanel { left: 18px; }
#chronologyPanel {
right: 18px;
width: 300px;
max-height: calc(100vh - 132px);
}
.panel h2 {
margin: 0 0 4px;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #dbe8e5;
}
.panel-intro {
margin: 0 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.section {
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid rgba(184, 213, 210, 0.12);
}
.section:first-of-type {
margin-top: 0;
padding-top: 0;
border-top: 0;
}
.check {
position: relative;
display: grid;
grid-template-columns: 18px 1fr;
gap: 9px;
align-items: start;
margin: 9px 0;
cursor: pointer;
user-select: none;
}
.check input {
appearance: none;
width: 16px;
height: 16px;
margin: 1px 0 0;
border: 1px solid #527074;
border-radius: 4px;
background: rgba(255,255,255,0.04);
cursor: pointer;
}
.check input:checked {
border-color: var(--accent);
background:
linear-gradient(135deg, transparent 43%, #092129 44% 54%, transparent 55%),
var(--accent);
}
.check input:focus-visible {
outline: 2px solid var(--accent-warm);
outline-offset: 2px;
}
.check-title {
display: block;
color: #e5eeec;
font-size: 12px;
line-height: 1.25;
}
.check-note {
display: block;
margin-top: 2px;
color: #91a7aa;
font-size: 10px;
line-height: 1.35;
}
.route-check {
margin-left: 27px;
padding-left: 10px;
border-left: 1px solid rgba(178, 211, 207, 0.13);
}
.route-swatch {
display: inline-block;
width: 14px;
height: 3px;
margin-right: 5px;
vertical-align: middle;
border-radius: 3px;
background: currentColor;
box-shadow: 0 0 7px currentColor;
}
#dateValue {
margin: 4px 0 7px;
color: #f0f5f3;
font-family: Georgia, "Times New Roman", serif;
font-size: 25px;
font-weight: 500;
}
#snapshotText {
min-height: 58px;
margin: 0;
color: #aebfc0;
font-size: 11px;
line-height: 1.5;
}
#timeline {
width: 100%;
margin: 13px 0 3px;
accent-color: var(--accent);
cursor: pointer;
}
.timeline-ticks {
display: flex;
justify-content: space-between;
color: #789095;
font-size: 9px;
}
.timeline-controls {
display: flex;
gap: 7px;
margin-top: 11px;
}
.timeline-controls button {
flex: 1;
padding: 7px 8px;
font-size: 10px;
}
#regionList {
margin: 12px 0 0;
padding: 0;
list-style: none;
}
#regionList li {
position: relative;
padding: 5px 0 5px 13px;
color: #a9bec0;
font-size: 10px;
line-height: 1.3;
border-top: 1px solid rgba(255,255,255,0.045);
}
#regionList li::before {
content: "";
position: absolute;
left: 0;
top: 9px;
width: 5px;
height: 5px;
border-radius: 50%;
background: #79bfe3;
box-shadow: 0 0 8px rgba(121, 191, 227, 0.5);
}
.legend-panel {
position: fixed;
z-index: 9;
right: 18px;
bottom: 16px;
width: 300px;
padding: 12px 14px;
border: 1px solid var(--panel-edge);
border-radius: 10px;
background: rgba(9, 23, 29, 0.85);
color: var(--muted);
font-size: 10px;
line-height: 1.35;
backdrop-filter: blur(10px);
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin: 5px 0;
}
.legend-symbol {
width: 21px;
height: 12px;
flex: 0 0 auto;
border-radius: 3px;
}
.legend-symbol.envelope {
border: 1px dashed rgba(121, 191, 227, 0.8);
background: rgba(121, 191, 227, 0.16);
}
.legend-symbol.route {
height: 0;
border-top: 2px dashed #78c6bb;
border-radius: 0;
}
.legend-symbol.site {
width: 10px;
height: 10px;
margin-left: 5px;
margin-right: 6px;
background: #d6a65d;
transform: rotate(45deg);
border-radius: 1px;
}
.legend-symbol.ring {
border: 2px solid rgba(215, 164, 199, 0.75);
background: transparent;
border-radius: 50%;
}
.legend-note {
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid rgba(255,255,255,0.08);
color: #d9b58e;
}
#controlsHint {
position: fixed;
z-index: 8;
left: 19px;
bottom: 18px;
color: rgba(197, 216, 215, 0.58);
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
text-shadow: 0 1px 4px #000;
}
#statusStrip {
position: fixed;
z-index: 8;
left: 50%;
bottom: 18px;
transform: translateX(-50%);
padding: 6px 10px;
border-radius: 20px;
background: rgba(9, 23, 29, 0.65);
color: rgba(211, 226, 224, 0.65);
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
#tooltip {
position: fixed;
z-index: 30;
display: none;
max-width: 285px;
pointer-events: none;
padding: 10px 12px;
border: 1px solid rgba(213, 185, 126, 0.35);
border-radius: 8px;
background: rgba(8, 20, 25, 0.95);
box-shadow: 0 12px 28px rgba(0,0,0,0.35);
font-size: 11px;
line-height: 1.4;
}
#tooltip strong {
display: block;
margin-bottom: 3px;
color: #f0d19d;
font-family: Georgia, "Times New Roman", serif;
font-size: 14px;
font-weight: 500;
}
#tooltip span { color: #a9b9b9; }
dialog {
width: min(680px, calc(100vw - 30px));
max-height: calc(100vh - 40px);
padding: 0;
border: 1px solid rgba(180, 216, 210, 0.28);
border-radius: 14px;
color: var(--ink);
background: #0d2027;
box-shadow: 0 30px 80px rgba(0,0,0,0.55);
}
dialog::backdrop {
background: rgba(3, 10, 14, 0.7);
backdrop-filter: blur(4px);
}
.dialog-inner {
padding: 24px;
}
.dialog-inner h2 {
margin: 0 0 6px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
}
.dialog-inner p,
.dialog-inner li {
color: #b8c8c8;
font-size: 13px;
line-height: 1.6;
}
.dialog-inner ul { padding-left: 20px; }
.dialog-inner strong { color: #e6efec; }
.dialog-actions {
display: flex;
justify-content: flex-end;
margin-top: 20px;
}
.panel-hidden #evidencePanel {
display: none;
}
@media (max-width: 850px) {
.topbar {
left: 10px;
right: 10px;
top: 10px;
}
.brand {
max-width: calc(100vw - 112px);
padding: 11px 13px;
}
.subtitle { display: none; }
.top-actions {
position: absolute;
right: 0;
top: 0;
}
.top-actions .button {
padding: 8px 10px;
font-size: 11px;
}
.panel {
top: 91px;
max-height: 47vh;
}
#evidencePanel {
left: 10px;
width: min(260px, calc(100vw - 20px));
}
#chronologyPanel {
right: 10px;
bottom: 10px;
top: auto;
width: min(278px, calc(100vw - 20px));
max-height: 42vh;
}
.legend-panel, #statusStrip { display: none; }
#controlsHint {
left: 10px;
bottom: 10px;
max-width: 45vw;
}
}
@media (max-width: 520px) {
#chronologyPanel {
width: calc(100vw - 20px);
max-height: 34vh;
}
#evidencePanel {
max-height: 38vh;
}
}
</style>
</head>
<body>
<canvas id="scene" tabindex="0"
aria-label="Interactive schematic map of historical Bantu-language expansion hypotheses. Drag to orbit, shift-drag to pan, and scroll to zoom.">
</canvas>
<div id="labels" aria-hidden="true"></div>
<header class="topbar">
<div class="brand">
<div class="eyebrow">Schematic evidence explorer · c. 2000 BCE–1000 CE</div>
<h1>Bantu-Language Expansions</h1>
<p class="subtitle">
A contested landscape of language, archaeology, ancestry, climate, and overlapping route hypotheses.
</p>
</div>
<div class="top-actions">
<button class="button" id="panelToggle" aria-expanded="true">Layers</button>
<button class="button primary" id="infoButton">How to read</button>
</div>
</header>
<aside class="panel" id="evidencePanel" aria-label="Evidence layers">
<h2>Evidence layers</h2>
<p class="panel-intro">
Toggle independent proxies. Their overlap does not prove a single migration route.
</p>
<div class="section">
<label class="check">
<input type="checkbox" id="languageLayer" checked>
<span>
<span class="check-title">Language-range envelopes</span>
<span class="check-note">Approximate areas reconstructed from linguistic comparison; deliberately translucent.</span>
</span>
</label>
<label class="check">
<input type="checkbox" id="archaeologyLayer" checked>
<span>
<span class="check-title">Archaeological proxies</span>
<span class="check-note">Selected pottery, iron, farming, and settlement contexts. These do not directly date languages.</span>
</span>
</label>
<label class="check">
<input type="checkbox" id="geneticsLayer">
<span>
<span class="check-title">Genetic ancestry proxies</span>
<span class="check-note">Broad, model-dependent population patterns; not equivalent to language distributions.</span>
</span>
</label>
<label class="check">
<input type="checkbox" id="climateLayer">
<span>
<span class="check-title">Habitat corridors</span>
<span class="check-note">Schematic forest and savanna possibilities reconstructed from climate proxies.</span>
</span>
</label>
</div>
<div class="section">
<h2>Alternative route hypotheses</h2>
<p class="panel-intro" style="margin-top: 6px; margin-bottom: 8px;">
Selected, overlapping possibilities—not a consensus sequence and not a single arrow.
</p>
<label class="check">
<input type="checkbox" id="allRoutes" checked>
<span>
<span class="check-title">Show route hypotheses</span>
</span>
</label>
<label class="check route-check" style="color: #78c6bb;">
<input type="checkbox" class="routeToggle" data-route="eastern" checked>
<span>
<span class="check-title"><i class="route-swatch"></i>Eastern interior arc</span>
<span class="check-note">Through the Congo basin and Great Lakes toward eastern Africa.</span>
</span>
</label>
<label class="check route-check" style="color: #e1aa68;">
<input type="checkbox" class="routeToggle" data-route="western" checked>
<span>
<span class="check-title"><i class="route-swatch"></i>Benin–Bight / western forest</span>
<span class="check-note">A western branch associated with the later Kwan expansion.</span>
</span>
</label>
<label class="check route-check" style="color: #9caee0;">
<input type="checkbox" class="routeToggle" data-route="savanna" checked>
<span>
<span class="check-title"><i class="route-swatch"></i>Niger–Benue corridor</span>
<span class="check-note">A north-central river and savanna connection with several possible contacts.</span>
</span>
</label>
<label class="check route-check" style="color: #cf92b6;">
<input type="checkbox" class="routeToggle" data-route="zambezi" checked>
<span>
<span class="check-title"><i class="route-swatch"></i>Zambezi corridor</span>
<span class="check-note">A southeastern path whose timing and direction remain debated.</span>
</span>
</label>
</div>
<div class="section">
<label class="check">
<input type="checkbox" id="labelsToggle" checked>
<span>
<span class="check-title">Place and layer labels</span>
</span>
</label>
<label class="check">
<input type="checkbox" id="graticuleToggle" checked>
<span>
<span class="check-title">Latitude / longitude grid</span>
</span>
</label>
</div>
</aside>
<aside class="panel" id="chronologyPanel" aria-label="Expansion chronology">
<h2>Chronological hypothesis</h2>
<div id="dateValue">c. 1 CE</div>
<p id="snapshotText"></p>
<input id="timeline" type="range" min="0" max="5" step="1" value="3"
aria-label="Select chronological snapshot">
<div class="timeline-ticks" aria-hidden="true">
<span>2000 BCE</span>
<span>1000</span>
<span>500</span>
<span>1 CE</span>
<span>500</span>
<span>1000</span>
</div>
<div class="timeline-controls">
<button class="button" id="previousDate" aria-label="Previous date">← Earlier</button>
<button class="button" id="playTimeline" aria-label="Play chronology">▶ Play</button>
<button class="button" id="nextDate" aria-label="Next date">Later →</button>
</div>
<ul id="regionList" aria-label="Areas shown in this snapshot"></ul>
<div class="section">
<p class="panel-intro" style="margin: 0;">
<strong style="color:#d8e6e2;">Important:</strong>
A range envelope is an uncertainty model, not a hard border. Language communities,
multilingualism, and non-Bantu languages make real distributions more complex.
</p>
</div>
</aside>
<aside class="legend-panel" aria-label="Map legend">
<div class="legend-row">
<span class="legend-symbol envelope"></span>
<span>Translucent fill + dashed edge: uncertain range envelope</span>
</div>
<div class="legend-row">
<span class="legend-symbol route"></span>
<span>Dashed path: illustrative expansion hypothesis</span>
</div>
<div class="legend-row">
<span class="legend-symbol site"></span>
<span>Archaeological context used as an indirect proxy</span>
</div>
<div class="legend-row">
<span class="legend-symbol ring"></span>
<span>Broad population-genomic proxy</span>
</div>
<div class="legend-note">
No single arrow is treated as a complete explanation. Paths may overlap, coexist, or represent different phases.
</div>
</aside>
<div id="controlsHint">Drag: orbit · Shift/right-drag: pan · Scroll: zoom · R: reset</div>
<div id="statusStrip">Schematic synthesis · Not to scale · Approximate dates</div>
<div id="tooltip" role="status" aria-live="polite"></div>
<dialog id="infoDialog">
<div class="dialog-inner">
<div class="eyebrow">Interpretation guide</div>
<h2>How to read this map</h2>
<p>
This is an exploratory teaching graphic, not a reconstruction intended to settle
the history of the Bantu-language family. It emphasizes uncertainty and competing
explanations rather than presenting a single, linear migration.
</p>
<ul>
<li><strong>Language envelopes</strong> show broad reconstructed ranges at selected
chronological snapshots. Their soft, irregular edges represent uncertainty rather
than accepted political or linguistic borders.</li>
<li><strong>Archaeological markers</strong> identify selected contexts relevant to
ceramic technology, metallurgy, farming, trade, or settlement. An archaeological
context cannot by itself identify the language spoken there.</li>
<li><strong>Genetic proxies</strong> summarize broad ancestry patterns inferred from
population data and models. Modern and ancient genomes do not map neatly onto
languages, and shared ancestry may predate any linguistic expansion.</li>
<li><strong>Habitat corridors</strong> are deliberately schematic. Paleoclimate
reconstructions differ by proxy, period, and resolution.</li>
<li><strong>Route hypotheses</strong> are selected alternatives that overlap. The
western Kwan expansion, eastern interior dispersals, river contacts, pastoral
interactions, and local language shift may have operated at different times.</li>
<li><strong>Bantu is a branch of Niger–Congo.</strong> Many African language
families and communities are not represented by these Bantu-language envelopes.</li>
</ul>
<p>
Dates are approximate comparative chronologies rather than the dates at which a
language was first written. The map deliberately omits modern borders.
</p>
<div class="dialog-actions">
<button class="button primary" id="closeInfo">Return to map</button>
</div>
</div>
</dialog>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Basic setup
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091820);
scene.fog = new THREE.FogExp2(0x091820, 0.0065);
const camera = new THREE.PerspectiveCamera(
41,
window.innerWidth / window.innerHeight,
0.1,
220
);
const hemisphere = new THREE.HemisphereLight(0xb8dbe0, 0x33281c, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffedcf, 2.3);
sun.position.set(-24, 48, 25);
scene.add(sun);
const fill = new THREE.DirectionalLight(0x79aeb9, 0.8);
fill.position.set(38, 22, -35);
scene.add(fill);
const mapRoot = new THREE.Group();
const geographyGroup = new THREE.Group();
const climateGroup = new THREE.Group();
const geneticsGroup = new THREE.Group();
const archaeologyGroup = new THREE.Group();
const languageGroup = new THREE.Group();
const routeGroup = new THREE.Group();
const originGroup = new THREE.Group();
const graticuleGroup = new THREE.Group();
scene.add(
mapRoot,
geographyGroup,
climateGroup,
geneticsGroup,
archaeologyGroup,
languageGroup,
routeGroup,
originGroup,
graticuleGroup
);
const MAP = {
lon0: 15,
lat0: 5,
scale: 0.9
};
function ll(lon, lat, y = 0) {
return new THREE.Vector3(
(lon - MAP.lon0) * MAP.scale,
y,
-(lat - MAP.lat0) * MAP.scale
);
}
function shapeFromPoints(points) {
const shape = new THREE.Shape();
shape.moveTo(
(points[0][0] - MAP.lon0) * MAP.scale,
(points[0][1] - MAP.lat0) * MAP.scale
);
for (let i = 1; i < points.length; i++) {
shape.lineTo(
(points[i][0] - MAP.lon0) * MAP.scale,
(points[i][1] - MAP.lat0) * MAP.scale
);
}
shape.closePath();
return shape;
}
function horizontalShape(points, y, material) {
const geometry = new THREE.ShapeGeometry(shapeFromPoints(points));
geometry.rotateX(-Math.PI / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = y;
mesh.renderOrder = 3;
return mesh;
}
function dashedLine(points, color, opacity = 0.7, dashSize = 0.55, gapSize = 0.36) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize,
gapSize,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 7;
return line;
}
function seededRandom(seed) {
const x = Math.sin(seed * 12.9898 + 78.233) * 43758.5453;
return x - Math.floor(x);
}
// -------------------------------------------------------------------------
// Low-poly geography
// -------------------------------------------------------------------------
const africaOutline = [
[-17, 15], [-17, 21], [-13, 26], [-7, 31], [-1, 35],
[8, 37], [18, 33], [25, 32], [32, 31], [35, 28],
[37, 22], [40, 16], [43, 11], [51, 12], [49, 5],
[43, 0], [40, -8], [37, -17], [33, -25], [27, -34],
[20, -35], [15, -27], [12, -18], [9, -1], [4, 5],
[-4, 5], [-9, 4], [-13, 8]
];
const madagascarOutline = [
[49, -13], [50, -16], [49, -20], [47, -25],
[44, -25], [44, -21], [47, -17]
];
const ocean = new THREE.Mesh(
new THREE.PlaneGeometry(150, 135),
new THREE.MeshStandardMaterial({
color: 0x102d38,
roughness: 0.92,
metalness: 0.02
})
);
ocean.rotation.x = -Math.PI / 2;
ocean.position.y = -0.22;
scene.add(ocean);
const oceanGrid = new THREE.GridHelper(132, 24, 0x31505a, 0x19343d);
oceanGrid.position.y = -0.18;
oceanGrid.material.transparent = true;
oceanGrid.material.opacity = 0.22;
scene.add(oceanGrid);
const landMaterial = new THREE.MeshStandardMaterial({
color: 0x52614c,
roughness: 1,
flatShading: true
});
const africaBase = horizontalShape(africaOutline, 0.015, landMaterial);
geographyGroup.add(africaBase);
const madagascarMaterial = new THREE.MeshStandardMaterial({
color: 0x59684d,
roughness: 1,
flatShading: true
});
geographyGroup.add(horizontalShape(madagascarOutline, 0.025, madagascarMaterial));
function pointInPolygon(x, y, polygon) {
let inside = false;
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
const xi = polygon[i][0], yi = polygon[i][1];
const xj = polygon[j][0], yj = polygon[j][1];
const intersects =
((yi > y) !== (yj > y)) &&
(x < ((xj - xi) * (y - yi)) / (yj - yi) + xi);
if (intersects) inside = !inside;
}
return inside;
}
function biomeColor(lon, lat, variation) {
const c = new THREE.Color();
let base;
if (lat < 8 && lon > 5 && lon < 28) {
base = new THREE.Color(0x285844);
} else if (lat > 8 && lat < 18 && lon > 14) {
base = new THREE.Color(0x797047);
} else if (lat > 16 && lon < 13) {
base = new THREE.Color(0x8e7951);
} else if (lon > 25 && lat < -13) {
base = new THREE.Color(0x6f7049);
} else if (lat < -18) {
base = new THREE.Color(0x77704d);
} else {
base = new THREE.Color(0x66704a);
}
c.copy(base);
c.offsetHSL(
(seededRandom(lon * 4.7 + lat * 9.2) - 0.5) * 0.025,
(variation - 0.5) * 0.08,
(variation - 0.5) * 0.12
);
return c;
}
function buildFacets() {
const positions = [];
const colors = [];
const step = 4.6;
let faceIndex = 0;
for (let lat = 34; lat > -34; lat -= step) {
for (let lon = -16; lon < 50; lon += step) {
const corners = [
[lon, lat],
[lon + step, lat],
[lon + step, lat - step],
[lon, lat - step]
];
if (!corners.every(([x, y]) => pointInPolygon(x, y, africaOutline))) {
continue;
}
const diagonal = (faceIndex++ % 2 === 0)
? [[0, 1, 2], [0, 2, 3]]
: [[0, 1, 3], [1, 2, 3]];
for (const tri of diagonal) {
const variation = seededRandom(lon * 3.1 + lat * 8.3 + faceIndex);
const color = biomeColor(lon + step / 2, lat - step / 2, variation);
for (const index of tri) {
const [x, y] = corners[index];
const jx = x + (seededRandom(x * 3.7 + y * 5.1) - 0.5) * 1.5;
const jy = y + (seededRandom(x * 7.2 + y * 2.4) - 0.5) * 1.5;
const p = ll(jx, jy);
const elevation = 0.10 +
Math.sin(jx * 0.28) * 0.055 +
Math.cos(jy * 0.21) * 0.04 +
variation * 0.035;
positions.push(p.x, elevation, p.z);
colors.push(color.r, color.g, color.b);
}
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.96,
flatShading: true,
side: THREE.DoubleSide
})
);
mesh.renderOrder = 1;
geographyGroup.add(mesh);
}
buildFacets();
const coastPoints = africaOutline.map(([lon, lat]) => ll(lon, lat, 0.32));
coastPoints.push(coastPoints[0].clone());
const coast = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(coastPoints),
new THREE.LineBasicMaterial({
color: 0x9bb4a8,
transparent: true,
opacity: 0.46
})
);
geographyGroup.add(coast);
const madagascarPoints = madagascarOutline.map(([lon, lat]) => ll(lon, lat, 0.32));
madagascarPoints.push(madagascarPoints[0].clone());
geographyGroup.add(new THREE.Line(
new THREE.BufferGeometry().setFromPoints(madagascarPoints),
new THREE.LineBasicMaterial({
color: 0x9bb4a8,
transparent: true,
opacity: 0.46
})
));
// Orientation rivers; these are geographic references, not migration arrows.
const riverData = [
{
color: 0x4c8490,
points: [[-5, 14], [-1, 11], [2, 8], [7, 8], [11, 7], [15, 8]]
},
{
color: 0x4c8490,
points: [[17, 8], [19, 5], [18, 1], [14, -2], [15, -6], [12, -8]]
},
{
color: 0x4c8490,
points: [[22, -12], [25, -15], [29, -17], [33, -18], [36, -20]]
},
{
color: 0x4c8490,
points: [[30, -20], [28, -23], [27, -27], [24, -29], [19, -29]]
}
];
for (const river of riverData) {
const curve = new THREE.CatmullRomCurve3(
river.points.map(([lon, lat]) => ll(lon, lat, 0.39))
);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(80)),
new THREE.LineBasicMaterial({
color: river.color,
transparent: true,
opacity: 0.52
})
);
geographyGroup.add(line);
}
// Graticule
for (let lon = -20; lon <= 55; lon += 10) {
const points = [];
for (let lat = -36; lat <= 38; lat += 2) points.push(ll(lon, lat, 0.43));
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0x8ca8a8,
transparent: true,
opacity: 0.115,
depthWrite: false
})
);
graticuleGroup.add(line);
}
for (let lat = -30; lat <= 30; lat += 10) {
const points = [];
for (let lon = -20; lon <= 52; lon += 2) points.push(ll(lon, lat, 0.43));
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0x8ca8a8,
transparent: true,
opacity: 0.115,
depthWrite: false
})
);
graticuleGroup.add(line);
}
// -------------------------------------------------------------------------
// Habitat corridors
// -------------------------------------------------------------------------
const climateRegions = [
{
name: "Cameroon–Congo forest possibility",
color: 0x8fae5c,
points: [
[7, 10], [12, 9], [19, 4], [24, 0], [29, -4],
[30, -10], [25, -15], [18, -10], [13, -5], [8, 1]
]
},
{
name: "Western savanna possibility",
color: 0xb09b59,
points: [
[-2, 14], [4, 13], [9, 9], [11, 3], [8, -3],
[4, -3], [0, 2], [-3, 8]
]
},
{
name: "Eastern woodland corridor",
color: 0x799865,
points: [
[28, -2], [33, -6], [37, -11], [37, -20],
[33, -28], [28, -29], [25, -22], [27, -12]
]
}
];
for (const region of climateRegions) {
const material = new THREE.MeshBasicMaterial({
color: region.color,
transparent: true,
opacity: 0.13,
depthWrite: false,
side: THREE.DoubleSide
});
const fill = horizontalShape(region.points, 0.20, material);
climateGroup.add(fill);
const outline = dashedLine(
region.points.map(([lon, lat]) => ll(lon, lat, 0.27)),
region.color,
0.5,
0.6,
0.4
);
climateGroup.add(outline);
}
// -------------------------------------------------------------------------
// Broad genetic ancestry proxies
// -------------------------------------------------------------------------
const geneticRegions = [
{ name: "Cameroon–Congo ancestry proxy", lon: 12, lat: 3, radius: 6.5 },
{ name: "Great Lakes ancestry proxy", lon: 28, lat: -6, radius: 6.8 },
{ name: "Western ancestry proxy", lon: 10, lat: -10, radius: 5.2 }
];
for (const region of geneticRegions) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(region.radius * 0.73, region.radius, 48),
new THREE.MeshBasicMaterial({
color: 0xcf92b6,
transparent: true,
opacity: 0.25,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.copy(ll(region.lon, region.lat, 0.34));
geneticsGroup.add(ring);
const disc = new THREE.Mesh(
new THREE.CircleGeometry(region.radius * 0.74, 40),
new THREE.MeshBasicMaterial({
color: 0xcf92b6,
transparent: true,
opacity: 0.045,
side: THREE.DoubleSide,
depthWrite: false
})
);
disc.rotation.x = -Math.PI / 2;
disc.position.copy(ll(region.lon, region.lat, 0.32));
geneticsGroup.add(disc);
}
// -------------------------------------------------------------------------
// Archaeological proxy sites
// -------------------------------------------------------------------------
const sites = [
{
name: "Bokol Madik",
place: "Cameroon",
date: "c. 2000 BCE",
note: "Early pottery context. Its relationship to language identification is debated.",
lon: 10.9, lat: 6.1
},
{
name: "Okun",
place: "Nigeria",
date: "c. 1000 BCE",
note: "Early pottery tradition used in discussions of early Niger–Congo dispersals.",
lon: 6.2, lat: 7.8
},
{
name: "Nkumbululu",
place: "Democratic Republic of the Congo",
date: "c. 500 BCE",
note: "Early iron-working context; an archaeological proxy rather than a language marker.",
lon: 27.4, lat: -5.9
},
{
name: "Igbo-Ukwu",
place: "Nigeria",
date: "c. 9th century CE",
note: "Ironworking, textiles, and long-distance exchange in an eastern Nigeria region.",
lon: 6.8, lat: 6.3
},
{
name: "Ntusi",
place: "Zambia",
date: "c. 500–900 CE",
note: "Early farming and settlement evidence relevant to southern African dispersals.",
lon: 26.2, lat: -15.5
},
{
name: "Manyikeni",
place: "Mozambique",
date: "c. 500–900 CE",
note: "Large agricultural settlement associated with regional exchange networks.",
lon: 34.8, lat: -20.2
},
{
name: "Lydenburg",
place: "South Africa",
date: "c. 5th–8th centuries CE",
note: "Early Iron Age agricultural and craft contexts; language assignment is indirect.",
lon: -29.8, lat: -24.5
}
];
const markerMeshes = [];
for (const site of sites) {
const group = new THREE.Group();
group.position.copy(ll(site.lon, site.lat, 0));
const stem = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.32, 0),
new THREE.Vector3(0, 0.9, 0)
]),
new THREE.LineBasicMaterial({
color: 0xd6a65d,
transparent: true,
opacity: 0.52
})
);
group.add(stem);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.38, 0),
new THREE.MeshStandardMaterial({
color: 0xe0b16b,
emissive: 0x4b2c0c,
emissiveIntensity: 0.45,
roughness: 0.7,
flatShading: true
})
);
marker.position.y = 1.05;
marker.userData.site = site;
marker.userData.label = site.name;
group.add(marker);
markerMeshes.push(marker);
const halo = new THREE.Mesh(
new THREE.RingGeometry(0.48, 0.58, 18),
new THREE.MeshBasicMaterial({
color: 0xe0b16b,
transparent: true,
opacity: 0.45,
side: THREE.DoubleSide,
depthWrite: false
})
);
halo.rotation.x = -Math.PI / 2;
halo.position.y = 0.47;
group.add(halo);
archaeologyGroup.add(group);
}
// -------------------------------------------------------------------------
// Selected, overlapping route hypotheses
// -------------------------------------------------------------------------
const routeDefinitions = {
eastern: {
name: "Eastern interior arc",
color: 0x78c6bb,
points: [
[8.5, 6], [14, 2], [21, -1], [27, -4],
[31, -9], [31, -17], [26, -25], [20, -30]
],
label: [29, -10]
},
western: {
name: "Benin–Bight / western forest",
color: 0xe1aa68,
points: [
[6, 7], [9, 1], [9, -6], [11, -12],
[15, -17], [17, -23]
],
label: [9, -9]
},
savanna: {
name: "Niger–Benue corridor",
color: 0x9caee0,
points: [
[2, 10], [0, 5], [5, 0], [12, -4], [18, -6]
],
label: [4, 8]
},
zambezi: {
name: "Zambezi corridor",
color: 0xcf92b6,
points: [
[19, -4], [24, -9], [29, -16], [32, -23], [28, -30]
],
label: [30, -23]
}
};
const routeObjects = {};
for (const [id, route] of Object.entries(routeDefinitions)) {
const group = new THREE.Group();
const curve = new THREE.CatmullRomCurve3(
route.points.map(([lon, lat]) => ll(lon, lat, 0.61)),
false,
"catmullrom",
0.35
);
// A broad transparent envelope emphasizes uncertainty without depicting an arrow.
const envelope = new THREE.Mesh(
new THREE.TubeGeometry(curve, 70, 0.68, 6, false),
new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.085,
depthWrite: false,
side: THREE.DoubleSide
})
);
envelope.renderOrder = 5;
group.add(envelope);
const path = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(curve.getPoints(180)),
new THREE.LineDashedMaterial({
color: route.color,
transparent: true,
opacity: 0.92,
dashSize: 0.9,
gapSize: 0.48,
depthWrite: false
})
);
path.computeLineDistances();
path.renderOrder = 8;
group.add(path);
// Small nodes mark contact/waypoint hypotheses rather than a continuous migration front.
for (let i = 0; i < route.points.length; i += 2) {
const [lon, lat] = route.points[i];
const node = new THREE.Mesh(
new THREE.OctahedronGeometry(0.19, 0),
new THREE.MeshBasicMaterial({
color: route.color,
transparent: true,
opacity: 0.9
})
);
node.position.copy(ll(lon, lat, 0.65));
group.add(node);
}
routeGroup.add(group);
routeObjects[id] = { group, route };
}
// A softly pulsing proposed core, rather than a fixed point of origin.
const originMaterial = new THREE.MeshBasicMaterial({
color: 0x8ccce2,
transparent: true,
opacity: 0.58,
side: THREE.DoubleSide,
depthWrite: false
});
const originRing = new THREE.Mesh(
new THREE.RingGeometry(0.72, 0.82, 32),
originMaterial
);
originRing.rotation.x = -Math.PI / 2;
originRing.position.copy(ll(9, 5, 0.52));
originGroup.add(originRing);
const originCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.38, 0),
new THREE.MeshStandardMaterial({
color: 0xa9d9e9,
emissive: 0x245866,
emissiveIntensity: 0.7,
roughness: 0.7,
flatShading: true
})
);
originCore.position.copy(ll(9, 5, 0.88));
originGroup.add(originCore);
// -------------------------------------------------------------------------
// Chronological language envelopes
// -------------------------------------------------------------------------
const snapshots = [
{
date: "c. 2000 BCE",
text: "A small proposed Proto-Bantu core is shown in the Cameroon–Nigeria region. The precise location and date of the ancestral language remain debated.",
regions: [
{ name: "Proposed Cameroon–Nigeria core", lon: 9, lat: 5.5, rx: 5.2, ry: 4.1 }
]
},
{
date: "c. 1000 BCE",
text: "Compact range hypotheses occupy the Niger–Benue and Cameroon–Congo regions. A western precursor area is separated, but evidence for language boundaries is indirect.",
regions: [
{ name: "Proposed Cameroon–Nigeria core", lon: 9, lat: 5.5, rx: 6.2, ry: 4.8 },
{ name: "Western coastal precursor hypothesis", lon: 3, lat: 7.5, rx: 4.7, ry: 3.8 }
]
},
{
date: "c. 500 BCE",
text: "Broader early-range hypotheses are dominated by central and western Africa. The envelopes allow for substantial uncertainty and alternative contacts.",
regions: [
{ name: "Niger–Benue core hypothesis", lon: 9, lat: 5, rx: 7.1, ry: 5.4 },
{ name: "Western forest / Kwan precursor", lon: 10, lat: -9, rx: 4.7, ry: 7.1 }
]
},
{
date: "c. 1 CE",
text: "Several dispersed expansion hypotheses are compared. Central African, Great Lakes, and western forest areas appear, without implying a single departure or timetable.",
regions: [
{ name: "Central African range hypothesis", lon: 14, lat: -2, rx: 8.8, ry: 7.2 },
{ name: "Eastern interior hypothesis", lon: 27, lat: -6, rx: 7.1, ry: 7.8 },
{ name: "Western forest hypothesis", lon: 10, lat: -13, rx: 5.4, ry: 7.2 }
]
},
{
date: "c. 500 CE",
text: "Hypothesized interior and coastal corridors are broader. Gaps in the record may reflect uneven evidence, changing ecology, or genuinely different histories.",
regions: [
{ name: "Central African range hypothesis", lon: 15, lat: -3, rx: 9.4, ry: 7.7 },
{ name: "Eastern interior hypothesis", lon: 29, lat: -10, rx: 8.0, ry: 9.2 },
{ name: "Western forest hypothesis", lon: 10, lat: -14, rx: 6.0, ry: 8.0 },
{ name: "Southern interior hypothesis", lon: 18, lat: -23, rx: 7.8, ry: 5.0 }
]
},
{
date: "c. 1000 CE",
text: "Many communities associated with Bantu languages are present across central, eastern, and southern Africa. This schematic envelope is not a complete census of language communities.",
regions: [
{ name: "Central African range hypothesis", lon: 15, lat: -4, rx: 10.0, ry: 8.1 },
{ name: "Eastern African range hypothesis", lon: 30, lat: -14, rx: 8.2, ry: 11.0 },
{ name: "Western forest hypothesis", lon: 10, lat: -14, rx: 6.4, ry: 8.6 },
{ name: "Southern African range hypothesis", lon: 21, lat: -26, rx: 9.0, ry: 6.3 }
]
}
];
function irregularRegionPoints(region, seed) {
const points = [];
const count = 22;
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
const wobble =
0.90 +
Math.sin(angle * 3 + seed) * 0.065 +
Math.sin(angle * 5 - seed * 0.7) * 0.035 +
(seededRandom(seed * 17 + i) - 0.5) * 0.075;
points.push([
region.lon + Math.cos(angle) * region.rx * wobble,
region.lat + Math.sin(angle) * region.ry * wobble
]);
}
return points;
}
function clearGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((m) => m.dispose());
} else {
object.material.dispose();
}
}
});
}
}
function buildLanguageSnapshot(index) {
clearGroup(languageGroup);
const snapshot = snapshots[index];
snapshot.regions.forEach((region, regionIndex) => {
const points = irregularRegionPoints(region, index * 3.7 + regionIndex + 1);
const fill = horizontalShape(
points,
0.29,
new THREE.MeshBasicMaterial({
color: 0x75b8df,
transparent: true,
opacity: 0.10,
side: THREE.DoubleSide,
depthWrite: false
})
);
languageGroup.add(fill);
const outline = dashedLine(
points.map(([lon, lat]) => ll(lon, lat, 0.36)),
0x8fd4ef,
0.68,
0.52,
0.34
);
languageGroup.add(outline);
});
document.getElementById("dateValue").textContent = snapshot.date;
document.getElementById("snapshotText").textContent = snapshot.text;
const regionList = document.getElementById("regionList");
regionList.innerHTML = "";
for (const region of snapshot.regions) {
const li = document.createElement("li");
li.textContent = region.name;
regionList.appendChild(li);
}
}
buildLanguageSnapshot(3);
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelObjects = [];
const labelsContainer = document.getElementById("labels");
function addLabel(text, lon, lat, options = {}) {
const element = document.createElement("div");
element.className = "map-label" + (options.className ? " " + options.className : "");
element.textContent = text;
if (options.color) element.style.color = options.color;
labelsContainer.appendChild(element);
labelObjects.push({
element,
position: ll(lon, lat, options.y || 0.75),
layer: options.layer || "geo",
route: options.route || null,
visible: options.visible !== false
});
}
addLabel("ATLANTIC OCEAN", -9, 6, { className: "geo", y: 0.2 });
addLabel("INDIAN OCEAN", 43, -9, { className: "geo", y: 0.2 });
addLabel("Cameroon–Nigeria", 8, 10, { layer: "language" });
addLabel("Congo basin", 15, -5, { layer: "language" });
addLabel("Great Lakes", 29, -1, { layer: "language" });
addLabel("Western forest", 8, -16, { layer: "language" });
addLabel("Zambezi–Limpopo", 26, -28, { layer: "language" });
addLabel("Eastern interior arc", 29, -10, {
className: "route",
layer: "route",
route: "eastern",
color: "#9ee2d8"
});
addLabel("Benin–Bight / western", 9, -9, {
className: "route",
layer: "route",
route: "western",
color: "#f0c68f"
});
addLabel("Niger–Benue", 4, 8, {
className: "route",
layer: "route",
route: "savanna",
color: "#bdc8f3"
});
addLabel("Zambezi corridor", 30, -23, {
className: "route",
layer: "route",
route: "zambezi",
color: "#e4b1cf"
});
addLabel("Forest possibility", 18, 4, {
className: "climate", layer: "climate", color: "#c8bf7a"
});
addLabel("Savanna possibility", 4, 12, {
className: "climate", layer: "climate", color: "#c8bf7a"
});
addLabel("Woodland possibility", 33, -18, {
className: "climate", layer: "climate", color: "#c8bf7a"
});
addLabel("Ancestry proxy", 12, 3, {
className: "genetic", layer: "genetics", color: "#d7a4c7"
});
addLabel("Ancestry proxy", 28, -6, {
className: "genetic", layer: "genetics", color: "#d7a4c7"
});
addLabel("Ancestry proxy", 10, -10, {
className: "genetic", layer: "genetics", color: "#d7a4c7"
});
const layerVisibility = {
language: true,
archaeology: true,
genetics: false,
climate: false,
route: true,
geo: true
};
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelObjects) {
const p = label.position.clone().project(camera);
const visible =
label.visible &&
layerVisibility[label.layer] &&
p.z > -1 && p.z < 1 &&
p.x > -1.08 && p.x < 1.08 &&
p.y > -1.08 && p.y < 1.08;
label.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (p.x * 0.5 + 0.5) * width;
const y = (-p.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Custom orbit / pan / zoom camera controls
// -------------------------------------------------------------------------
const desired = {
radius: 58,
theta: 0.16,
phi: 0.86,
target: new THREE.Vector3(7, 0, -4)
};
const current = {
radius: desired.radius,
theta: desired.theta,
phi: desired.phi,
target: desired.target.clone()
};
let dragging = false;
let dragMoved = false;
let previousPointer = { x: 0, y: 0 };
let pointerInside = false;
const pointerNdc = new THREE.Vector2(10, 10);
let pointerClient = { x: 0, y: 0 };
function resetCamera() {
desired.radius = 58;
desired.theta = 0.16;
desired.phi = 0.86;
desired.target.set(7, 0, -4);
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
canvas.focus();
});
canvas.addEventListener("pointermove", (event) => {
pointerInside = true;
pointerClient = { x: event.clientX, y: event.clientY };
pointerNdc.x = (event.clientX / window.innerWidth) * 2 - 1;
pointerNdc.y = -(event.clientY / window.innerHeight) * 2 + 1;
if (!dragging) return;
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
previousPointer = { x: event.clientX, y: event.clientY };
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
if (event.shiftKey || event.button === 2) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const forward = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 2);
forward.y = 0;
forward.normalize();
const panScale = desired.radius * 0.0015;
desired.target.addScaledVector(right, -dx * panScale);
desired.target.addScaledVector(forward, dy * panScale);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -22, 34);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -28, 28);
} else {
desired.theta -= dx * 0.005;
desired.phi = THREE.MathUtils.clamp(desired.phi - dy * 0.005, 0.26, 1.42);
}
});
function stopDragging(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("pointerleave", () => {
pointerInside = false;
document.getElementById("tooltip").style.display = "none";
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
22,
95
);
}, { passive: false });
canvas.addEventListener("keydown", (event) => {
const step = 0.09;
if (event.key === "ArrowLeft") desired.theta += step;
if (event.key === "ArrowRight") desired.theta -= step;
if (event.key === "ArrowUp") desired.phi = Math.max(0.26, desired.phi - step);
if (event.key === "ArrowDown") desired.phi = Math.min(1.42, desired.phi + step);
if (event.key === "+" || event.key === "=") desired.radius = Math.max(22, desired.radius - 3);
if (event.key === "-") desired.radius = Math.min(95, desired.radius + 3);
if (event.key.toLowerCase() === "r") resetCamera();
});
function updateCamera() {
current.radius += (desired.radius - current.radius) * 0.09;
current.theta += (desired.theta - current.theta) * 0.11;
current.phi += (desired.phi - current.phi) * 0.11;
current.target.lerp(desired.target, 0.11);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + current.radius * sinPhi * Math.sin(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(current.target);
camera.updateMatrixWorld();
}
// -------------------------------------------------------------------------
// UI state
// -------------------------------------------------------------------------
const languageInput = document.getElementById("languageLayer");
const archaeologyInput = document.getElementById("archaeologyLayer");
const geneticsInput = document.getElementById("geneticsLayer");
const climateInput = document.getElementById("climateLayer");
const allRoutesInput = document.getElementById("allRoutes");
const routeToggles = [...document.querySelectorAll(".routeToggle")];
const labelsInput = document.getElementById("labelsToggle");
const graticuleInput = document.getElementById("graticuleToggle");
function updateRouteVisibility() {
const master = allRoutesInput.checked;
for (const toggle of routeToggles) {
const id = toggle.dataset.route;
routeObjects[id].group.visible = master && toggle.checked;
}
layerVisibility.route = master;
}
function updateLayers() {
languageGroup.visible = languageInput.checked;
originGroup.visible = languageInput.checked;
archaeologyGroup.visible = archaeologyInput.checked;
geneticsGroup.visible = geneticsInput.checked;
climateGroup.visible = climateInput.checked;
graticuleGroup.visible = graticuleInput.checked;
layerVisibility.language = languageInput.checked;
layerVisibility.archaeology = archaeologyInput.checked;
layerVisibility.genetics = geneticsInput.checked;
layerVisibility.climate = climateInput.checked;
layerVisibility.geo = labelsInput.checked;
updateRouteVisibility();
}
languageInput.addEventListener("change", updateLayers);
archaeologyInput.addEventListener("change", updateLayers);
geneticsInput.addEventListener("change", updateLayers);
climateInput.addEventListener("change", updateLayers);
allRoutesInput.addEventListener("change", updateRouteVisibility);
routeToggles.forEach((toggle) => toggle.addEventListener("change", updateRouteVisibility));
labelsInput.addEventListener("change", updateLayers);
graticuleInput.addEventListener("change", updateLayers);
const timeline = document.getElementById("timeline");
timeline.addEventListener("input", () => {
stopPlayback();
buildLanguageSnapshot(Number(timeline.value));
});
document.getElementById("previousDate").addEventListener("click", () => {
stopPlayback();
timeline.value = Math.max(0, Number(timeline.value) - 1);
buildLanguageSnapshot(Number(timeline.value));
});
document.getElementById("nextDate").addEventListener("click", () => {
stopPlayback();
timeline.value = Math.min(5, Number(timeline.value) + 1);
buildLanguageSnapshot(Number(timeline.value));
});
let playbackTimer = null;
const playButton = document.getElementById("playTimeline");
function stopPlayback() {
if (playbackTimer) clearInterval(playbackTimer);
playbackTimer = null;
playButton.textContent = "▶ Play";
}
playButton.addEventListener("click", () => {
if (playbackTimer) {
stopPlayback();
return;
}
playButton.textContent = "❚❚ Pause";
playbackTimer = setInterval(() => {
const next = (Number(timeline.value) + 1) % snapshots.length;
timeline.value = next;
buildLanguageSnapshot(next);
}, 1550);
});
const infoDialog = document.getElementById("infoDialog");
document.getElementById("infoButton").addEventListener("click", () => {
stopPlayback();
infoDialog.showModal();
});
document.getElementById("closeInfo").addEventListener("click", () => infoDialog.close());
const panelToggle = document.getElementById("panelToggle");
panelToggle.addEventListener("click", () => {
const hidden = document.body.classList.toggle("panel-hidden");
panelToggle.setAttribute("aria-expanded", String(!hidden));
panelToggle.textContent = hidden ? "Show layers" : "Layers";
});
updateLayers();
// -------------------------------------------------------------------------
// Hover interaction for archaeological proxies
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const tooltip = document.getElementById("tooltip");
function updateHover() {
if (!pointerInside || dragging) {
tooltip.style.display = "none";
return;
}
raycaster.setFromCamera(pointerNdc, camera);
const intersections = raycaster.intersectObjects(markerMeshes, false);
if (intersections.length) {
const site = intersections[0].object.userData.site;
tooltip.innerHTML =
`<strong>${site.name}</strong>` +
`<span>${site.place} · ${site.date}<br>${site.note}</span>`;
tooltip.style.display = "block";
const width = 285;
const x = Math.min(
window.innerWidth - width - 12,
Math.max(12, pointerClient.x + 15)
);
const y = Math.min(
window.innerHeight - 120,
Math.max(12, pointerClient.y + 15)
);
tooltip.style.left = `${x}px`;
tooltip.style.top = `${y}px`;
} else {
tooltip.style.display = "none";
}
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
updateCamera();
const pulse = 1 + Math.sin(elapsed * 1.8) * 0.11;
originRing.scale.setScalar(pulse);
originMaterial.opacity = 0.42 + Math.sin(elapsed * 1.8) * 0.12;
originCore.rotation.y = elapsed * 0.32;
originCore.rotation.x = elapsed * 0.18;
updateLabels();
updateHover();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```