Three.js Family Tree (Genealogy Visualization)
A generated multi-generation family tree in Three.js with a tidy layout by subtree width, couples, married-in partners, and ancestor and descendant highlighting that cycles through family members.
Key topics: family tree visualization, genealogy, tidy tree layout, three.js tree, pedigree chart, hierarchy
Game Over
What this code does
- Generation: a founding couple has 1–4 children per family; most marry partners from outside the tree and continue the line.
- Tidy Layout: a couple's width is max(2, sum of children's widths), and children are centred beneath their parents, so branches never overlap.
- Connectors: orthogonal parent→child elbows hang from the midpoint of each couple's link.
- Highlighting: tree traversals up (ancestors, gold) and down (descendants, cyan) from the focused person.
- Auto-Fit: the camera distance is computed from the tree's width and the camera's field of view.
- Controls: generations, family seed, spacing, cycling or hold, and focus on the founder; names are fictional.
Related Demos
Continue Learning
JavaScript Implementation
// Tidy genealogy layout: width(couple) = max(2, Σ width(children)); children centred under parents
function width (p) { return Math.max(p.partner ? 2 : 1, p.children.reduce((s, c) => s + width(c), 0)) }
function place (p, x0) {
const cx = x0 + width(p) / 2 * W
p.x = p.partner ? cx - W / 2 : cx; if (p.partner) p.partner.x = cx + W / 2
p.y = -p.generation * 3
let x = x0 + (width(p) - p.children.reduce((s, c) => s + width(c), 0)) / 2 * W
for (const c of p.children) { place(c, x); x += width(c) * W }
}
// Draw each person as a THREE.Sprite card; orthogonal line segments join parents to children