Prompt specification
Build or customize the Three.js 3D scene "Variant population token board" 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: Variant population token board
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/variant-population-token-board-x0937
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing hereditary variation in a fictional population. Arrange a small fictional population with several trait colors and equal starting counts; label each color as a hereditary variant rather than a desired final form. Low-poly.
Working Three.js Starter (variant-population-token-board-x0937):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>One Population, Several Inherited Forms</title>
<style>
:root {
color-scheme: dark;
--bg: #091218;
--panel: rgba(13, 24, 31, 0.82);
--panel-border: rgba(218, 234, 238, 0.15);
--text: #edf5f5;
--muted: #9eb2b7;
--ochre: #e3a34a;
--teal: #36b9aa;
--amethyst: #a47add;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
overscroll-behavior: none;
}
#scene-container,
#labels {
position: fixed;
inset: 0;
}
#scene-container canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene-container canvas.dragging {
cursor: grabbing;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.masthead {
position: fixed;
z-index: 4;
top: 28px;
left: 30px;
width: min(520px, calc(100vw - 60px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: #bfd0d4;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 2px;
background: #dce9eb;
content: "";
}
h1 {
max-width: 490px;
margin: 0;
font-size: clamp(30px, 4vw, 52px);
font-weight: 660;
line-height: 0.98;
letter-spacing: -0.045em;
}
.masthead p {
max-width: 440px;
margin: 15px 0 0;
color: #b7c7ca;
font-size: 14px;
line-height: 1.55;
}
.controls {
position: fixed;
z-index: 5;
top: 28px;
right: 28px;
display: flex;
gap: 8px;
}
.control-button {
display: inline-flex;
align-items: center;
min-height: 38px;
padding: 0 13px;
border: 1px solid var(--panel-border);
border-radius: 999px;
background: var(--panel);
color: #dce8ea;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(14px);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.025em;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.control-button:hover {
border-color: rgba(230, 244, 246, 0.32);
background: rgba(25, 42, 50, 0.92);
transform: translateY(-1px);
}
.control-button:focus-visible {
outline: 2px solid #e6f4f4;
outline-offset: 3px;
}
.control-dot {
width: 6px;
height: 6px;
margin-right: 8px;
border-radius: 50%;
background: #dce9eb;
box-shadow: 0 0 9px rgba(220, 233, 235, 0.45);
}
.legend {
position: fixed;
z-index: 4;
bottom: 22px;
left: 50%;
width: min(790px, calc(100vw - 36px));
padding: 13px 14px 11px;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px);
transform: translateX(-50%);
}
.legend-topline {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 2px 9px;
color: #afc1c5;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-topline span:last-child {
letter-spacing: 0.05em;
text-transform: none;
}
.variant-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 8px;
}
.variant-card {
position: relative;
min-width: 0;
overflow: hidden;
padding: 10px 11px 9px;
border: 1px solid rgba(220, 235, 238, 0.11);
border-radius: 11px;
background: rgba(230, 244, 246, 0.035);
}
.variant-card::before {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 3px;
background: var(--swatch);
content: "";
}
.variant-main {
display: flex;
align-items: center;
min-width: 0;
}
.swatch {
flex: 0 0 auto;
width: 24px;
height: 24px;
margin-right: 10px;
border: 1px solid rgba(255, 255, 255, 0.28);
border-radius: 7px;
background: var(--swatch);
box-shadow:
inset 0 0 0 3px rgba(0, 0, 0, 0.09),
0 0 15px color-mix(in srgb, var(--swatch) 24%, transparent);
}
.variant-copy {
min-width: 0;
}
.variant-kind {
display: block;
margin-bottom: 2px;
color: #91a7ac;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
line-height: 1.2;
text-transform: uppercase;
}
.variant-name {
display: block;
overflow: hidden;
color: #eff7f7;
font-size: 13px;
font-weight: 680;
line-height: 1.2;
text-overflow: ellipsis;
white-space: nowrap;
}
.variant-count {
margin-left: auto;
padding-left: 8px;
color: #eff7f7;
font-size: 19px;
font-weight: 700;
line-height: 1;
}
.variant-count small {
color: #81979c;
font-size: 9px;
font-weight: 600;
}
.count-track {
height: 3px;
margin-top: 9px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.08);
}
.count-fill {
width: 33.333%;
height: 100%;
border-radius: inherit;
background: var(--swatch);
opacity: 0.86;
}
.legend-note {
margin: 9px 2px 0;
color: #91a5aa;
font-size: 10px;
line-height: 1.45;
}
.legend-note strong {
color: #c8d7da;
font-weight: 650;
}
.house-label {
position: absolute;
top: 0;
left: 0;
padding: 5px 8px 4px;
border: 1px solid rgba(222, 238, 240, 0.16);
border-radius: 7px;
background: rgba(11, 22, 28, 0.76);
color: #dce9eb;
box-shadow: 0 5px 16px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(7px);
text-align: center;
transform: translate(-50%, -100%);
white-space: nowrap;
}
.house-label span {
display: block;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
}
.house-label small {
display: block;
margin-top: 1px;
color: #82989e;
font-size: 7px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#tooltip {
position: fixed;
z-index: 8;
display: none;
width: 215px;
padding: 12px 13px;
border: 1px solid rgba(225, 240, 242, 0.18);
border-radius: 12px;
background: rgba(10, 21, 27, 0.94);
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
pointer-events: none;
backdrop-filter: blur(12px);
}
#tooltip strong {
display: block;
margin-bottom: 2px;
color: #f0f7f7;
font-size: 14px;
}
#tooltip .tooltip-house,
#tooltip .tooltip-role {
display: block;
color: #91a6ab;
font-size: 10px;
line-height: 1.45;
}
#tooltip .tooltip-variant {
display: flex;
align-items: center;
gap: 7px;
margin-top: 9px;
color: #e4eeee;
font-size: 11px;
font-weight: 650;
}
#tooltip .tooltip-variant::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--tooltip-color);
content: "";
}
#tooltip .tooltip-note {
display: block;
margin-top: 7px;
padding-top: 7px;
border-top: 1px solid rgba(255, 255, 255, 0.09);
color: #8ea3a8;
font-size: 9px;
line-height: 1.4;
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #091218;
color: #b8c9cc;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.masthead {
top: 17px;
left: 17px;
width: calc(100vw - 34px);
}
.eyebrow {
margin-bottom: 7px;
font-size: 8px;
}
h1 {
max-width: 330px;
font-size: 29px;
}
.masthead p {
max-width: 285px;
margin-top: 9px;
font-size: 11px;
}
.controls {
top: 127px;
right: 14px;
}
.control-button {
min-height: 34px;
padding: 0 10px;
font-size: 9px;
}
.legend {
bottom: 10px;
width: calc(100vw - 20px);
padding: 10px 9px 9px;
border-radius: 13px;
}
.legend-topline {
margin-bottom: 7px;
font-size: 8px;
}
.variant-grid {
gap: 5px;
}
.variant-card {
padding: 8px 7px 7px;
}
.variant-main {
display: block;
}
.swatch {
width: 17px;
height: 17px;
margin: 0 0 6px;
border-radius: 5px;
}
.variant-kind {
min-height: 18px;
font-size: 6px;
line-height: 1.25;
}
.variant-name {
font-size: 10px;
}
.variant-count {
position: absolute;
top: 7px;
right: 7px;
font-size: 14px;
}
.variant-count small {
display: none;
}
.count-track {
margin-top: 7px;
}
.legend-note {
margin-top: 7px;
font-size: 8px;
}
.house-label {
padding: 4px 6px 3px;
}
.house-label span {
font-size: 6px;
}
.house-label small {
display: none;
}
}
@media (max-height: 600px) {
.masthead p {
display: none;
}
.controls {
top: 18px;
}
.legend {
bottom: 8px;
}
}
</style>
</head>
<body>
<div id="scene-container"></div>
<div id="labels" aria-hidden="true"></div>
<header class="masthead">
<div class="eyebrow">The Lumen Archive · Population Study 03</div>
<h1>One population.<br>Several inherited forms.</h1>
<p>
The fictional Lumen people begin with 18 residents and three inherited
coat variants—six residents in each variant.
</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button
id="lineage-button"
class="control-button"
type="button"
aria-pressed="true"
>
<span class="control-dot"></span>
<span id="lineage-button-text">Hide family links</span>
</button>
<button id="reset-button" class="control-button" type="button">
Reset view
</button>
</nav>
<section class="legend" aria-label="Starting population counts">
<div class="legend-topline">
<span>Starting population · inherited coat hue</span>
<span>18 residents total</span>
</div>
<div class="variant-grid">
<article class="variant-card" style="--swatch: var(--ochre)">
<div class="variant-main">
<span class="swatch" aria-hidden="true"></span>
<div class="variant-copy">
<span class="variant-kind">Hereditary variant 01</span>
<strong class="variant-name">Ochre coat</strong>
</div>
<div class="variant-count" id="count-ochre">6<small>/18</small></div>
</div>
<div class="count-track" aria-hidden="true">
<div class="count-fill"></div>
</div>
</article>
<article class="variant-card" style="--swatch: var(--teal)">
<div class="variant-main">
<span class="swatch" aria-hidden="true"></span>
<div class="variant-copy">
<span class="variant-kind">Hereditary variant 02</span>
<strong class="variant-name">Teal coat</strong>
</div>
<div class="variant-count" id="count-teal">6<small>/18</small></div>
</div>
<div class="count-track" aria-hidden="true">
<div class="count-fill"></div>
</div>
</article>
<article class="variant-card" style="--swatch: var(--amethyst)">
<div class="variant-main">
<span class="swatch" aria-hidden="true"></span>
<div class="variant-copy">
<span class="variant-kind">Hereditary variant 03</span>
<strong class="variant-name">Amethyst coat</strong>
</div>
<div class="variant-count" id="count-amethyst">6<small>/18</small></div>
</div>
<div class="count-track" aria-hidden="true">
<div class="count-fill"></div>
</div>
</article>
</div>
<p class="legend-note">
<strong>Equal starting counts.</strong>
Every color is a hereditary variant—not a ranking, goal, or desired
final form. Hover over a resident to inspect the population.
</p>
</section>
<div id="tooltip" role="status" aria-live="polite"></div>
<div id="loading">Loading the Lumen population…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const sceneContainer = document.getElementById("scene-container");
const labelsContainer = document.getElementById("labels");
const tooltip = document.getElementById("tooltip");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly view of a fictional population with three inherited coat variants."
);
sceneContainer.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091218);
scene.fog = new THREE.Fog(0x091218, 26, 54);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.7, 0);
const spherical = new THREE.Spherical();
let azimuth = 0;
let polar = 1.03;
let userZoomed = false;
function defaultRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.65) return 42;
if (aspect < 1) return 31;
return 23.5;
}
let radius = defaultRadius();
function updateCamera() {
spherical.set(radius, polar, azimuth);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xc4e9ef,
0x28372f,
1.85
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe5bf, 3.1);
sun.position.set(8, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x86bfd0, 1.05);
fillLight.position.set(-9, 6, -7);
scene.add(fillLight);
const world = new THREE.Group();
scene.add(world);
// -------------------------------------------------------------------------
// Variant definitions
// -------------------------------------------------------------------------
const variants = {
ochre: {
name: "Ochre",
hex: 0xe3a34a,
css: "#e3a34a"
},
teal: {
name: "Teal",
hex: 0x36b9aa,
css: "#36b9aa"
},
amethyst: {
name: "Amethyst",
hex: 0xa47add,
css: "#a47add"
}
};
// Six illustrative households. Their combined starting counts are:
// Ochre = 6, Teal = 6, Amethyst = 6.
// Each child's displayed variant is also present in one of its parents.
const families = [
{
name: "Moss",
x: -4.6,
z: -2.3,
members: [
{ name: "Ada", role: "Parent", variant: "ochre" },
{ name: "Bex", role: "Parent", variant: "teal" },
{ name: "Cael", role: "Child", variant: "ochre" }
]
},
{
name: "Tide",
x: 0,
z: -2.3,
members: [
{ name: "Dara", role: "Parent", variant: "teal" },
{ name: "Elin", role: "Parent", variant: "amethyst" },
{ name: "Fen", role: "Child", variant: "amethyst" }
]
},
{
name: "Fern",
x: 4.6,
z: -2.3,
members: [
{ name: "Gia", role: "Parent", variant: "ochre" },
{ name: "Hal", role: "Parent", variant: "teal" },
{ name: "Ivo", role: "Child", variant: "teal" }
]
},
{
name: "Bloom",
x: -4.6,
z: 2.2,
members: [
{ name: "Jules", role: "Parent", variant: "ochre" },
{ name: "Kara", role: "Parent", variant: "amethyst" },
{ name: "Lux", role: "Child", variant: "amethyst" }
]
},
{
name: "Pine",
x: 0,
z: 2.2,
members: [
{ name: "Mika", role: "Parent", variant: "ochre" },
{ name: "Niko", role: "Parent", variant: "amethyst" },
{ name: "Orla", role: "Child", variant: "ochre" }
]
},
{
name: "Vale",
x: 4.6,
z: 2.2,
members: [
{ name: "Pax", role: "Parent", variant: "teal" },
{ name: "Quinn", role: "Parent", variant: "amethyst" },
{ name: "Rhea", role: "Child", variant: "teal" }
]
}
];
const variantCounts = {
ochre: 0,
teal: 0,
amethyst: 0
};
for (const family of families) {
for (const member of family.members) {
variantCounts[member.variant] += 1;
}
}
for (const key of Object.keys(variantCounts)) {
const badge = document.getElementById(`count-${key}`);
badge.innerHTML = `${variantCounts[key]}<small>/18</small>`;
}
// -------------------------------------------------------------------------
// Low-poly island and water
// -------------------------------------------------------------------------
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x12303b,
roughness: 0.92,
metalness: 0.04,
flatShading: true
});
const water = new THREE.Mesh(
new THREE.CircleGeometry(34, 32),
waterMaterial
);
water.rotation.x = -Math.PI / 2;
water.position.y = -1.08;
water.receiveShadow = true;
world.add(water);
const shoreMaterial = new THREE.MeshStandardMaterial({
color: 0x395f62,
roughness: 0.95,
transparent: true,
opacity: 0.38,
depthWrite: false
});
for (let i = 0; i < 3; i++) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(11.3 + i * 1.45, 11.42 + i * 1.45, 32),
shoreMaterial.clone()
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = -1.035 - i * 0.002;
ring.material.opacity = 0.25 - i * 0.055;
world.add(ring);
}
const islandBase = new THREE.Mesh(
new THREE.CylinderGeometry(10.55, 11.1, 1.05, 9),
new THREE.MeshStandardMaterial({
color: 0x786f58,
roughness: 1,
flatShading: true
})
);
islandBase.position.y = -0.57;
islandBase.receiveShadow = true;
islandBase.castShadow = true;
world.add(islandBase);
const grassTop = new THREE.Mesh(
new THREE.CylinderGeometry(10.48, 10.48, 0.18, 9),
new THREE.MeshStandardMaterial({
color: 0x526d56,
roughness: 1,
flatShading: true
})
);
grassTop.position.y = 0;
grassTop.receiveShadow = true;
world.add(grassTop);
const sandyRim = new THREE.Mesh(
new THREE.CylinderGeometry(10.74, 10.74, 0.08, 9),
new THREE.MeshStandardMaterial({
color: 0xa39268,
roughness: 1,
flatShading: true
})
);
sandyRim.position.y = -0.055;
sandyRim.receiveShadow = true;
world.add(sandyRim);
// A stylized low-poly sun in the distant sky.
const sunDisc = new THREE.Mesh(
new THREE.IcosahedronGeometry(1.05, 1),
new THREE.MeshBasicMaterial({
color: 0xf3c17a,
fog: false
})
);
sunDisc.position.set(-9, 10, -12);
scene.add(sunDisc);
// -------------------------------------------------------------------------
// Decorative plants and rocks
// -------------------------------------------------------------------------
let randomSeed = 7341;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x59483a,
roughness: 1,
flatShading: true
});
const crownMaterials = [
new THREE.MeshStandardMaterial({
color: 0x345746,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x456a51,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x56755a,
roughness: 1,
flatShading: true
})
];
function addTree(x, z, scale) {
const tree = new THREE.Group();
tree.position.set(x, 0.1, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.11, 0.16, 1.05, 5),
trunkMaterial
);
trunk.position.y = 0.52;
trunk.castShadow = true;
tree.add(trunk);
const lowerCrown = new THREE.Mesh(
new THREE.ConeGeometry(0.67, 1.25, 6),
crownMaterials[Math.floor(random() * crownMaterials.length)]
);
lowerCrown.position.y = 1.45;
lowerCrown.castShadow = true;
tree.add(lowerCrown);
const upperCrown = new THREE.Mesh(
new THREE.ConeGeometry(0.48, 1.05, 6),
crownMaterials[Math.floor(random() * crownMaterials.length)]
);
upperCrown.position.y = 2.0;
upperCrown.castShadow = true;
tree.add(upperCrown);
world.add(tree);
}
for (let i = 0; i < 17; i++) {
const angle = (i / 17) * Math.PI * 2 + random() * 0.15;
const treeRadius = 8.7 + random() * 1.15;
const x = Math.cos(angle) * treeRadius;
const z = Math.sin(angle) * treeRadius;
addTree(x, z, 0.68 + random() * 0.34);
}
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0x727970,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 22; i++) {
const angle = random() * Math.PI * 2;
const rockRadius = 7.8 + random() * 2;
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.18 + random() * 0.25, 0),
rockMaterial
);
rock.position.set(
Math.cos(angle) * rockRadius,
0.16,
Math.sin(angle) * rockRadius
);
rock.rotation.set(random() * 2, random() * 2, random() * 2);
rock.scale.y = 0.65 + random() * 0.5;
rock.castShadow = true;
rock.receiveShadow = true;
world.add(rock);
}
// -------------------------------------------------------------------------
// Population
// -------------------------------------------------------------------------
const clickableMeshes = [];
const familyLabels = [];
const lineageGroup = new THREE.Group();
world.add(lineageGroup);
const skinMaterials = [
new THREE.MeshStandardMaterial({
color: 0xc9936d,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x9e684c,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xe0b18a,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x754936,
roughness: 0.9,
flatShading: true
})
];
const hairMaterial = new THREE.MeshStandardMaterial({
color: 0x282522,
roughness: 1,
flatShading: true
});
const memberOffsets = [
new THREE.Vector3(-0.62, 0, -0.32),
new THREE.Vector3(0.62, 0, -0.32),
new THREE.Vector3(0, 0, 0.78)
];
function createPerson(member, family, position) {
const group = new THREE.Group();
group.position.copy(position);
group.rotation.y = (random() - 0.5) * 0.12;
group.scale.setScalar(0.91 + random() * 0.13);
const variant = variants[member.variant];
const coatMaterial = new THREE.MeshStandardMaterial({
color: variant.hex,
roughness: 0.78,
metalness: 0,
emissive: variant.hex,
emissiveIntensity: 0.035,
flatShading: true
});
const skinMaterial = skinMaterials[
Math.floor(random() * skinMaterials.length)
];
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.39, 0.88, 5),
coatMaterial
);
torso.position.y = 0.91;
torso.castShadow = true;
torso.receiveShadow = true;
group.add(torso);
const head = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.29, 0),
skinMaterial
);
head.position.y = 1.61;
head.castShadow = true;
group.add(head);
const hair = new THREE.Mesh(
new THREE.CylinderGeometry(0.23, 0.29, 0.18, 6),
hairMaterial
);
hair.position.y = 1.84;
hair.rotation.z = (random() - 0.5) * 0.08;
hair.castShadow = true;
group.add(hair);
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.14, 4),
skinMaterial
);
nose.position.set(0, 1.61, 0.285);
nose.rotation.x = Math.PI / 2;
nose.castShadow = true;
group.add(nose);
const leftArm = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.11, 0.68, 5),
coatMaterial
);
leftArm.position.set(-0.34, 0.91, 0);
leftArm.rotation.z = -0.14;
leftArm.castShadow = true;
group.add(leftArm);
const rightArm = new THREE.Mesh(
new THREE.CylinderGeometry(0.085, 0.11, 0.68, 5),
coatMaterial
);
rightArm.position.set(0.34, 0.91, 0);
rightArm.rotation.z = 0.14;
rightArm.castShadow = true;
group.add(rightArm);
const leftHand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.09, 0),
skinMaterial
);
leftHand.position.set(-0.39, 0.55, 0);
leftHand.castShadow = true;
group.add(leftHand);
const rightHand = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.09, 0),
skinMaterial
);
rightHand.position.set(0.39, 0.55, 0);
rightHand.castShadow = true;
group.add(rightHand);
for (const offset of [-0.13, 0.13]) {
const leg = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.12, 0.54, 5),
hairMaterial
);
leg.position.set(offset, 0.27, 0);
leg.castShadow = true;
group.add(leg);
}
const info = {
...member,
family: family.name,
variantName: variant.name,
variantCss: variant.css
};
for (const mesh of [torso, head, leftArm, rightArm]) {
mesh.userData.personInfo = info;
clickableMeshes.push(mesh);
}
world.add(group);
return group;
}
for (const family of families) {
const familyRing = new THREE.Mesh(
new THREE.TorusGeometry(1.24, 0.026, 3, 24),
new THREE.MeshBasicMaterial({
color: 0xd4e2df,
transparent: true,
opacity: 0.28
})
);
familyRing.rotation.x = Math.PI / 2;
familyRing.position.set(family.x, 0.13, family.z);
world.add(familyRing);
const personGroups = [];
family.members.forEach((member, index) => {
const position = new THREE.Vector3(
family.x + memberOffsets[index].x,
0.1,
family.z + memberOffsets[index].z
);
const personGroup = createPerson(member, family, position);
personGroups.push({ group: personGroup, position, member });
});
// Two parent-to-child arcs per household.
const child = personGroups[2];
for (let parentIndex = 0; parentIndex < 2; parentIndex++) {
const parent = personGroups[parentIndex];
const start = parent.position.clone();
start.y = 1.18;
const end = child.position.clone();
end.y = 1.16;
const middle = start.clone().add(end).multiplyScalar(0.5);
middle.y = 2.24;
const curve = new THREE.QuadraticBezierCurve3(
start,
middle,
end
);
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(24)
);
const material = new THREE.LineBasicMaterial({
color: 0xc5d8d8,
transparent: true,
opacity: 0.36
});
lineageGroup.add(new THREE.Line(geometry, material));
}
const label = document.createElement("div");
label.className = "house-label";
label.innerHTML = `
<span>${family.name.toUpperCase()}</span>
<small>household</small>
`;
labelsContainer.appendChild(label);
familyLabels.push({
element: label,
position: new THREE.Vector3(family.x, 2.54, family.z - 0.1)
});
}
// -------------------------------------------------------------------------
// Tooltip and raycasting
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let hoveredInfo = null;
function pickPerson(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickableMeshes, false);
return hits.length ? hits[0].object.userData.personInfo : null;
}
function positionTooltip(clientX, clientY) {
const width = tooltip.offsetWidth || 215;
const height = tooltip.offsetHeight || 120;
let x = clientX + 16;
let y = clientY + 16;
if (x + width > window.innerWidth - 12) {
x = clientX - width - 16;
}
if (y + height > window.innerHeight - 12) {
y = clientY - height - 16;
}
tooltip.style.left = `${Math.max(12, x)}px`;
tooltip.style.top = `${Math.max(12, y)}px`;
}
function showTooltip(info, clientX, clientY) {
if (!info) {
tooltip.style.display = "none";
hoveredInfo = null;
return;
}
hoveredInfo = info;
tooltip.style.setProperty("--tooltip-color", info.variantCss);
tooltip.innerHTML = `
<strong>${info.name}</strong>
<span class="tooltip-house">${info.family} household</span>
<span class="tooltip-role">${info.role} in the starting population</span>
<span class="tooltip-variant">${info.variantName} coat</span>
<small class="tooltip-note">
Hereditary variant in this fictional population.
</small>
`;
tooltip.style.display = "block";
positionTooltip(clientX, clientY);
}
// -------------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel/pinch to zoom
// -------------------------------------------------------------------------
const activePointers = new Map();
let dragDistance = 0;
let pinchDistance = null;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragDistance = 0;
if (activePointers.size === 2) {
const points = [...activePointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
renderer.domElement.classList.add("dragging");
tooltip.style.display = "none";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!activePointers.has(event.pointerId)) {
const info = pickPerson(event.clientX, event.clientY);
showTooltip(info, event.clientX, event.clientY);
return;
}
const previous = activePointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragDistance += Math.abs(dx) + Math.abs(dy);
if (activePointers.size === 1) {
azimuth -= dx * 0.006;
polar = THREE.MathUtils.clamp(polar + dy * 0.005, 0.48, 1.33);
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
const nextDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance && nextDistance > 0) {
radius = THREE.MathUtils.clamp(
radius * (pinchDistance / nextDistance),
13,
55
);
userZoomed = true;
}
pinchDistance = nextDistance;
}
});
function finishPointer(event) {
const wasActive = activePointers.has(event.pointerId);
activePointers.delete(event.pointerId);
if (activePointers.size < 2) {
pinchDistance = null;
}
if (activePointers.size === 0) {
renderer.domElement.classList.remove("dragging");
if (wasActive && dragDistance < 7) {
const info = pickPerson(event.clientX, event.clientY);
showTooltip(info, event.clientX, event.clientY);
}
}
}
renderer.domElement.addEventListener("pointerup", finishPointer);
renderer.domElement.addEventListener("pointercancel", finishPointer);
renderer.domElement.addEventListener("pointerleave", () => {
if (activePointers.size === 0) {
showTooltip(null);
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
13,
55
);
userZoomed = true;
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const lineageButton = document.getElementById("lineage-button");
const lineageButtonText = document.getElementById("lineage-button-text");
let lineageVisible = true;
lineageButton.addEventListener("click", () => {
lineageVisible = !lineageVisible;
lineageGroup.visible = lineageVisible;
lineageButton.setAttribute("aria-pressed", String(lineageVisible));
lineageButtonText.textContent = lineageVisible
? "Hide family links"
: "Show family links";
});
document.getElementById("reset-button").addEventListener("click", () => {
azimuth = 0;
polar = 1.03;
radius = defaultRadius();
userZoomed = false;
});
// -------------------------------------------------------------------------
// Projection of HTML labels and resize handling
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateFamilyLabels() {
camera.updateMatrixWorld();
for (const item of familyLabels) {
projected.copy(item.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
item.element.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
item.element.style.left = `${x}px`;
item.element.style.top = `${y}px`;
}
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 720 ? 48 : 40;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
if (!userZoomed) {
radius = defaultRadius();
}
}
window.addEventListener("resize", onResize);
onResize();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
renderer.setAnimationLoop(() => {
updateCamera();
renderer.render(scene, camera);
updateFamilyLabels();
});
renderer.render(scene, camera);
updateFamilyLabels();
document.getElementById("loading")?.remove();
</script>
</body>
</html>
```