Prompt specification
Build or customize the Three.js 3D scene "Original Family Cast With Varied Proportions" 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: Original Family Cast With Varied Proportions
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/original-family-cast-with-varied-proportions-x3681
Scene Description Prompt:
Model an original multigenerational cast with varied heights, proportions, and clothing. Avoid equating age, body shape, or assistive devices with fixed personality or capability. Build this with Three.js from cdnjs as a low-poly scene in one self-contained HTML file.
Working Three.js Starter (original-family-cast-with-varied-proportions-x3681):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Common Ground — A Multigenerational Low-Poly Portrait</title>
<style>
:root {
--ink: #263238;
--muted: #637078;
--paper: rgba(255, 250, 240, 0.93);
--line: rgba(38, 50, 56, 0.15);
--accent: #e76f51;
--shadow: 0 12px 35px rgba(43, 49, 46, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #efe4d2;
color: var(--ink);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
button {
font: inherit;
}
.title-card {
position: fixed;
z-index: 5;
top: 18px;
left: 18px;
max-width: 370px;
padding: 15px 17px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: var(--shadow);
pointer-events: none;
}
.title-card h1 {
margin: 0;
font-size: clamp(1.35rem, 2.3vw, 2rem);
letter-spacing: -0.04em;
}
.title-card p {
margin: 5px 0 0;
color: var(--muted);
font-size: 0.86rem;
line-height: 1.4;
}
.profile {
position: fixed;
z-index: 5;
top: 18px;
right: 18px;
width: min(310px, calc(100vw - 36px));
padding: 17px;
border: 1px solid var(--line);
border-radius: 15px;
background: var(--paper);
box-shadow: var(--shadow);
pointer-events: none;
}
.profile .eyebrow {
margin: 0 0 4px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.profile h2 {
margin: 0;
font-size: 1.45rem;
letter-spacing: -0.035em;
}
.profile .meta {
margin: 3px 0 11px;
color: var(--muted);
font-size: 0.82rem;
}
.profile .bio,
.profile .detail {
margin: 0;
font-size: 0.88rem;
line-height: 1.48;
}
.profile .detail {
margin-top: 9px;
color: var(--muted);
}
.profile .detail strong {
color: var(--ink);
}
.profile .principle {
margin: 13px -17px -17px;
padding: 12px 17px;
border-top: 1px solid var(--line);
border-radius: 0 0 15px 15px;
color: var(--muted);
background: rgba(232, 225, 210, 0.55);
font-size: 0.72rem;
line-height: 1.42;
}
.cast-nav {
position: fixed;
z-index: 6;
bottom: 18px;
left: 50%;
display: flex;
gap: 7px;
max-width: calc(100vw - 30px);
padding: 7px;
transform: translateX(-50%);
overflow-x: auto;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: var(--shadow);
}
.cast-nav button {
flex: 0 0 auto;
padding: 9px 13px;
border: 1px solid transparent;
border-radius: 9px;
background: transparent;
color: var(--ink);
cursor: pointer;
transition: background 150ms ease, color 150ms ease, transform 150ms ease;
}
.cast-nav button:hover {
background: rgba(38, 50, 56, 0.08);
transform: translateY(-1px);
}
.cast-nav button[aria-pressed="true"] {
border-color: var(--button-accent, var(--accent));
background: var(--button-accent, var(--accent));
color: #fff;
}
.cast-nav button:focus-visible,
canvas:focus-visible {
outline: 3px solid #2878a5;
outline-offset: 3px;
}
.cast-nav .reset {
border-left: 1px solid var(--line);
border-radius: 0 9px 9px 0;
color: var(--muted);
font-weight: 700;
}
.hint {
position: fixed;
z-index: 4;
right: 18px;
bottom: 82px;
padding: 7px 10px;
border-radius: 8px;
background: rgba(255, 250, 240, 0.8);
color: var(--muted);
font-size: 0.7rem;
pointer-events: none;
}
@media (max-width: 760px) {
.title-card {
top: 10px;
left: 10px;
max-width: calc(100vw - 20px);
padding: 11px 13px;
}
.title-card p {
display: none;
}
.profile {
top: 80px;
right: 10px;
width: min(280px, calc(100vw - 20px));
padding: 13px;
}
.profile .principle {
margin: 10px -13px -13px;
padding: 10px 13px;
}
.cast-nav {
bottom: 9px;
max-width: calc(100vw - 18px);
padding: 5px;
}
.cast-nav button {
padding: 8px 10px;
font-size: 0.78rem;
}
.hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
transition: none !important;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive low-poly scene showing five multigenerational characters outside a community center. Drag to orbit, scroll to zoom, and select a person from the cast bar."
></canvas>
<header class="title-card">
<h1>Common Ground</h1>
<p>
Five neighbors, five kinds of expertise. A low-poly portrait of a
multigenerational community.
</p>
</header>
<aside id="profile" class="profile" aria-live="polite">
<p class="eyebrow">Meet the cast</p>
<h2>Common Ground</h2>
<p class="meta">Select a neighbor to learn more.</p>
<p class="bio">
The plaza is a place for maps, radio signals, bicycles, film, plants,
and conversation.
</p>
<p class="detail">
<strong>Camera:</strong> drag to orbit, scroll or pinch to zoom.
Arrow keys rotate; + and − zoom; R resets the view.
</p>
<p class="principle">
Age, build, and mobility aids are descriptive details, not shorthand
for personality or capability. Each person's interests and skills are
presented independently.
</p>
</aside>
<nav id="cast-nav" class="cast-nav" aria-label="Choose a character"></nav>
<div class="hint">Drag to orbit · Wheel to zoom · R to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const profile = document.querySelector("#profile");
const castNav = document.querySelector("#cast-nav");
const reducedMotion = matchMedia("(prefers-reduced-motion: reduce)").matches;
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xefe4d2);
scene.fog = new THREE.Fog(0xefe4d2, 19, 38);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xfff7df, 0x66766d, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1ce, 3.2);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xa9d7e8, 0.65);
rimLight.position.set(8, 6, -8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
function mesh(geometry, color, parent, x = 0, y = 0, z = 0) {
const object = new THREE.Mesh(
geometry,
color && color.isMaterial ? color : material(color)
);
object.position.set(x, y, z);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0) {
return mesh(new THREE.BoxGeometry(w, h, d), color, parent, x, y, z);
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
segments,
color,
x = 0,
y = 0,
z = 0
) {
return mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
color,
parent,
x,
y,
z
);
}
function sphere(
parent,
radius,
color,
x = 0,
y = 0,
z = 0,
sx = 1,
sy = 1,
sz = 1
) {
const object = mesh(
new THREE.SphereGeometry(radius, 10, 7),
color,
parent,
x,
y,
z
);
object.scale.set(sx, sy, sz);
return object;
}
function rod(parent, start, end, radius, color) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const object = mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 7),
color,
parent,
midpoint.x,
midpoint.y,
midpoint.z
);
object.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return object;
}
function icosahedron(parent, radius, color, x, y, z, scale = 1) {
const object = mesh(
new THREE.IcosahedronGeometry(radius, 0),
color,
parent,
x,
y,
z
);
object.scale.setScalar(scale);
return object;
}
function roundedRect(context, x, y, w, h, radius) {
context.beginPath();
context.roundRect(x, y, w, h, radius);
context.closePath();
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
// -------------------------------------------------------------------------
// Cast data: identities, clothing, proportions, and interests are independent
// -------------------------------------------------------------------------
const cast = [
{
id: "mika",
name: "Mika Reyes",
shortName: "Mika",
age: 8,
pronouns: "they/them",
height: 1.28,
x: -4.6,
z: 0.7,
build: 0.88,
skin: 0x955d3f,
hair: 0x27201c,
hairStyle: "curls",
top: "coat",
coat: 0xf0b735,
shirt: 0xffdb64,
pants: 0x365d7a,
shoes: 0xc94e3b,
sleeve: 0xf0b735,
longSleeves: true,
glasses: true,
seated: true,
accent: 0xf0b735,
bio: "Draws neighborhood maps and keeps a list of every new shop.",
detail: "Mika uses a manual wheelchair and carries folded maps in a side pouch."
},
{
id: "jules",
name: "Jules Okafor",
shortName: "Jules",
age: 16,
pronouns: "he/they",
height: 1.82,
x: -2.3,
z: -0.35,
build: 0.86,
skin: 0x6f432d,
hair: 0x1f1917,
hairStyle: "short",
top: "overalls",
coat: 0x4e91a4,
shirt: 0xe7783d,
pants: 0x315a70,
shoes: 0xe2d6b9,
sleeve: 0xe7783d,
longSleeves: false,
headphones: true,
armPose: "tool",
accent: 0x4e91a4,
bio: "Builds radio kits and hosts a late-night community request show.",
detail: "The open orange shirt and blue overalls make up a practical workshop uniform."
},
{
id: "sora",
name: "Sora Bell",
shortName: "Sora",
age: 37,
pronouns: "she/her",
height: 1.61,
x: 0,
z: -0.65,
build: 1.08,
skin: 0xe0ad83,
hair: 0x71352d,
hairStyle: "waves",
top: "jacket",
coat: 0xb34f38,
shirt: 0xf0d6a4,
pants: 0x3e4b52,
shoes: 0x47362e,
sleeve: 0xb34f38,
longSleeves: true,
apron: 0x497b78,
accent: 0xb34f38,
bio: "Repairs bicycles at a neighborhood co-op and teaches brake changes.",
detail: "Sora's apron and tool pouch are workshop gear, not a uniform for a personality type."
},
{
id: "devi",
name: "Devi Rao",
shortName: "Devi",
age: 54,
pronouns: "they/them",
height: 1.76,
x: 2.4,
z: -0.15,
build: 1.16,
skin: 0x7c4b32,
hair: 0xd8d4c8,
hairStyle: "short",
top: "poncho",
coat: 0x7d4e92,
shirt: 0xe7a13b,
pants: 0x303b55,
shoes: 0x282a31,
sleeve: 0x7d4e92,
longSleeves: true,
earrings: true,
beard: true,
armPose: "present",
accent: 0x7d4e92,
bio: "Programs outdoor film nights and makes projection maps from old posters.",
detail: "A broad silhouette, silver hair, and geometric poncho are simply Devi's chosen style."
},
{
id: "tavi",
name: "Tavi Chen",
shortName: "Tavi",
age: 76,
pronouns: "he/him",
height: 1.58,
x: 4.6,
z: 0.75,
build: 0.9,
skin: 0xc78f68,
hair: 0xc8c4bc,
hairStyle: "bun",
top: "cardigan",
coat: 0x477b63,
shirt: 0xe1b65a,
pants: 0x786b58,
shoes: 0x4b3b35,
sleeve: 0x477b63,
longSleeves: true,
glasses: true,
beard: true,
accent: 0x477b63,
bio: "Records oral histories and grows herbs on the community roof.",
detail: "Tavi wears a cardigan with repaired cuffs and carries a small field recorder."
}
];
// -------------------------------------------------------------------------
// Environment
// -------------------------------------------------------------------------
const ground = mesh(
new THREE.PlaneGeometry(48, 48),
material(0xd4c8ac),
scene,
0,
-0.12,
0
);
ground.rotation.x = -Math.PI / 2;
cylinder(
scene,
6.6,
6.6,
0.08,
48,
material(0xe8dcc3),
0,
-0.055,
0
);
cylinder(
scene,
3.1,
3.1,
0.025,
40,
material(0xd8b56f, { transparent: true, opacity: 0.45 }),
0,
-0.005,
-0.1
);
// Community building.
box(scene, 18, 4.7, 0.55, 0xead9b8, 0, 2.2, -6.9);
box(scene, 18.6, 0.34, 0.95, 0x536c67, 0, 4.65, -6.9);
box(scene, 17.5, 0.22, 0.12, 0xc87058, 0, 4.38, -6.38);
const doorColors = [0x3f7d8d, 0xc8694e, 0x6b8f62, 0xd6a64a, 0x77588a];
for (let i = 0; i < 5; i++) {
const x = -6.6 + i * 3.3;
box(scene, 1.25, 2.25, 0.09, doorColors[i], x, 1.0, -6.58);
box(scene, 1.48, 0.16, 0.18, 0xf3e8d0, x, 2.18, -6.48);
box(scene, 0.08, 0.08, 0.08, 0xf5d87d, x + 0.38, 0.9, -6.49);
if (i !== 2) {
box(scene, 1.25, 0.9, 0.08, 0xa6c6c5, x, 3.35, -6.58);
box(scene, 0.06, 0.95, 0.11, 0xf4ead6, x, 3.35, -6.49);
box(scene, 1.3, 0.06, 0.11, 0xf4ead6, x, 3.35, -6.49);
}
}
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 256;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#f2dfb6";
roundedRect(signContext, 10, 10, 1004, 236, 28);
signContext.fill();
signContext.fillStyle = "#334a47";
signContext.font = "700 88px system-ui, sans-serif";
signContext.textAlign = "center";
signContext.textBaseline = "middle";
signContext.fillText("COMMON GROUND", 512, 126);
const sign = mesh(
new THREE.PlaneGeometry(4.9, 1.22),
new THREE.MeshBasicMaterial({ map: canvasTexture(signCanvas) }),
scene,
0,
3.25,
-6.36
);
sign.castShadow = false;
// Planters beside the entrance.
for (const x of [-8.1, 8.1]) {
cylinder(scene, 0.55, 0.42, 0.7, 7, 0x9e6b4b, x, 0.25, -5.7);
icosahedron(scene, 0.8, 0x587b5c, x, 1.1, -5.7, 1.1);
icosahedron(scene, 0.55, 0x7d9b67, x + 0.35, 1.3, -5.55, 1);
}
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
cylinder(tree, 0.16, 0.25, 2.1, 7, 0x75543e, 0, 0.95, 0);
icosahedron(tree, 1.05, 0x6e8f64, 0, 2.45, 0, 1.15);
icosahedron(tree, 0.72, 0x89a875, -0.5, 2.55, 0.2);
icosahedron(tree, 0.67, 0x58795c, 0.55, 2.62, -0.1);
rod(tree, [-0.05, 1.65, 0], [-0.65, 2.25, 0.1], 0.07, 0x75543e);
rod(tree, [0.03, 1.85, 0], [0.62, 2.45, 0], 0.07, 0x75543e);
}
makeTree(-8.2, -3.5, 1.1);
makeTree(8.2, -3.8, 1.05);
makeTree(-7.8, 2.4, 0.82);
makeTree(7.9, 2.8, 0.84);
function makeBench(x, z, rotation = 0) {
const bench = new THREE.Group();
bench.position.set(x, 0, z);
bench.rotation.y = rotation;
scene.add(bench);
for (let i = 0; i < 3; i++) {
box(bench, 2.1, 0.12, 0.18, 0x8b6248, 0, 0.62, -0.24 + i * 0.22);
}
for (let i = 0; i < 3; i++) {
box(bench, 2.1, 0.12, 0.16, 0x8b6248, 0, 0.88 + i * 0.22, -0.38);
}
for (const side of [-0.78, 0.78]) {
rod(bench, [side, 0.05, 0.2], [side, 0.62, 0.2], 0.055, 0x3d4948);
rod(bench, [side, 0.05, -0.35], [side, 1.38, -0.35], 0.055, 0x3d4948);
rod(bench, [side, 0.65, 0.18], [side, 1.28, -0.38], 0.055, 0x3d4948);
}
}
makeBench(-7.2, -0.2, 0.18);
makeBench(7.15, -1.4, -0.25);
// String lights across the plaza.
rod(scene, [-7.3, -0.1, -4.7], [-7.3, 4.4, -4.7], 0.055, 0x4c5b57);
rod(scene, [7.3, -0.1, -4.7], [7.3, 4.4, -4.7], 0.055, 0x4c5b57);
const bulbColors = [0xf3c765, 0xe77f66, 0x80b6c2, 0xb8d19b];
for (let i = 0; i < 12; i++) {
const t0 = i / 12;
const t1 = (i + 1) / 12;
const x0 = -7.3 + t0 * 14.6;
const x1 = -7.3 + t1 * 14.6;
const y0 = 4.32 - Math.sin(t0 * Math.PI) * 0.65;
const y1 = 4.32 - Math.sin(t1 * Math.PI) * 0.65;
rod(scene, [x0, y0, -4.7], [x1, y1, -4.7], 0.012, 0x3c4745);
sphere(
scene,
0.075,
bulbColors[i % bulbColors.length],
x1,
y1 - 0.12,
-4.7,
1,
1.25,
1
);
}
// -------------------------------------------------------------------------
// Character construction
// -------------------------------------------------------------------------
const characters = [];
const pickMeshes = [];
function addHair(head, character) {
const hair = character.hair;
const radius = 0.239;
if (character.hairStyle === "curls") {
const positions = [
[-0.16, 0.15, 0.05],
[-0.08, 0.23, 0.02],
[0.05, 0.23, 0.03],
[0.16, 0.16, 0.02],
[-0.17, 0.08, -0.12],
[0.16, 0.08, -0.12],
[0, 0.2, -0.14],
[-0.08, 0.12, 0.17]
];
for (const [x, y, z] of positions) {
sphere(head, 0.115, hair, x, y, z, 1, 0.9, 1);
}
} else {
mesh(
new THREE.SphereGeometry(
radius,
10,
5,
0,
Math.PI * 2,
0,
Math.PI * 0.42
),
hair,
head,
0,
0.015,
0
);
box(head, 0.32, 0.075, 0.075, hair, 0.02, 0.105, 0.195);
}
if (character.hairStyle === "waves") {
sphere(head, 0.13, hair, -0.19, 0.06, -0.08, 0.9, 1.2, 0.9);
sphere(head, 0.13, hair, 0.19, 0.06, -0.08, 0.9, 1.2, 0.9);
box(head, 0.34, 0.16, 0.08, hair, 0, -0.035, -0.18);
}
if (character.hairStyle === "bun") {
sphere(head, 0.115, hair, 0, 0.22, -0.18, 1, 1, 1);
box(head, 0.31, 0.18, 0.08, hair, 0, -0.04, -0.16);
}
}
function addFace(head, character) {
const skin = character.skin;
for (const side of [-1, 1]) {
sphere(head, 0.037, 0xf7f0df, side * 0.075, 0.018, 0.202, 1, 0.78, 0.55);
sphere(head, 0.018, 0x24211f, side * 0.075, 0.015, 0.221);
box(head, 0.075, 0.013, 0.014, character.hair, side * 0.078, 0.075, 0.214);
sphere(head, 0.043, skin, side * 0.223, -0.005, 0.005, 0.7, 1, 0.8);
}
sphere(head, 0.041, skin, 0, -0.01, 0.235, 0.7, 0.95, 0.85);
box(head, 0.075, 0.012, 0.013, 0x704a43, 0, -0.083, 0.211);
if (character.glasses) {
for (const side of [-1, 1]) {
const lens = mesh(
new THREE.TorusGeometry(0.069, 0.009, 5, 18),
0x3b3d3c,
head,
side * 0.075,
0.018,
0.226
);
lens.scale.y = 0.83;
}
rod(
head,
[-0.01, 0.018, 0.228],
[0.01, 0.018, 0.228],
0.009,
0x3b3d3c
);
}
if (character.headphones) {
sphere(head, 0.075, 0x30383a, -0.25, 0.01, 0, 0.65, 1, 1);
sphere(head, 0.075, 0x30383a, 0.25, 0.01, 0, 0.65, 1, 1);
rod(
head,
[-0.25, 0.04, 0],
[-0.13, 0.29, 0],
0.022,
0x30383a
);
rod(
head,
[-0.13, 0.29, 0],
[0.13, 0.29, 0],
0.022,
0x30383a
);
rod(
head,
[0.13, 0.29, 0],
[0.25, 0.04, 0],
0.022,
0x30383a
);
}
if (character.earrings) {
sphere(head, 0.028, 0xe4b84f, -0.23, -0.09, 0.015);
sphere(head, 0.028, 0xe4b84f, 0.23, -0.09, 0.015);
}
if (character.beard) {
sphere(
head,
0.14,
character.hair,
0,
-0.115,
0.11,
1.15,
0.7,
0.75
);
}
}
function dressTorso(parent, character, y = 1.08) {
const build = character.build;
const shirt = character.shirt;
if (character.top === "coat" || character.top === "jacket") {
cylinder(
parent,
0.255 * build,
0.33 * build,
0.64,
8,
character.coat,
0,
y - 0.045,
0
);
box(
parent,
0.035,
0.48,
0.026,
shirt,
0,
y - 0.01,
0.315 * build
);
for (const side of [-1, 1]) {
const lapel = box(
parent,
0.075,
0.22,
0.03,
character.coat,
side * 0.085,
y + 0.14,
0.316 * build
);
lapel.rotation.z = side * 0.38;
}
for (let i = 0; i < 3; i++) {
sphere(
parent,
0.022,
0xf5d77d,
0,
y + 0.07 - i * 0.13,
0.335 * build
);
}
} else {
cylinder(
parent,
0.235 * build,
0.265 * build,
0.54,
8,
shirt,
0,
y,
0
);
}
if (character.top === "overalls") {
box(
parent,
0.31 * build,
0.38,
0.045,
character.pants,
0,
y - 0.08,
0.25 * build
);
for (const side of [-1, 1]) {
box(
parent,
0.055,
0.45,
0.04,
character.pants,
side * 0.115 * build,
y + 0.04,
0.265 * build
);
sphere(
parent,
0.022,
0xe4b94f,
side * 0.115 * build,
y + 0.08,
0.291 * build
);
}
}
if (character.top === "poncho") {
cylinder(
parent,
0.27 * build,
0.48 * build,
0.61,
8,
character.coat,
0,
y - 0.06,
0
);
const pattern = [0xe6a23d, 0x4d9a93, 0xe4d3a1];
for (let row = 0; row < 2; row++) {
for (let col = -1; col <= 1; col++) {
const diamond = box(
parent,
0.09,
0.09,
0.025,
pattern[(row + col + 3) % pattern.length],
col * 0.16 * build,
y - 0.13 + row * 0.18,
0.385 - row * 0.065
);
diamond.rotation.z = Math.PI / 4;
}
}
}
if (character.top === "cardigan") {
for (const side of [-1, 1]) {
box(
parent,
0.115 * build,
0.55,
0.045,
character.coat,
side * 0.16 * build,
y,
0.252 * build
);
}
cylinder(
parent,
0.25 * build,
0.28 * build,
0.08,
8,
character.coat,
0,
y + 0.28,
0
);
}
if (character.apron) {
box(
parent,
0.31,
0.39,
0.045,
character.apron,
0,
y - 0.09,
0.29 * build
);
box(
parent,
0.07,
0.36,
0.035,
character.apron,
-0.085,
y + 0.04,
0.3 * build
);
box(
parent,
0.07,
0.36,
0.035,
character.apron,
0.085,
y + 0.04,
0.3 * build
);
box(
parent,
0.2,
0.14,
0.09,
0x72543f,
0.18 * build,
y - 0.19,
0.29 * build
);
}
}
function addArm(parent, character, side) {
const build = character.build;
const shoulder = new THREE.Group();
shoulder.position.set(side * (0.25 * build + 0.035), 1.29, 0);
shoulder.rotation.z = side * 0.12;
parent.add(shoulder);
cylinder(
shoulder,
0.076,
0.067,
0.27,
7,
character.sleeve,
0,
-0.135,
0
);
const elbow = new THREE.Group();
elbow.position.y = -0.27;
shoulder.add(elbow);
cylinder(
elbow,
0.064,
0.055,
0.25,
7,
character.longSleeves ? character.sleeve : character.skin,
0,
-0.125,
0
);
sphere(
elbow,
0.069,
character.skin,
0,
-0.285,
0,
0.9,
1.15,
0.85
);
if (character.armPose === "tool" && side === 1) {
shoulder.rotation.x = -0.72;
shoulder.rotation.z = -0.13;
elbow.rotation.x = -0.42;
}
if (character.armPose === "present" && side === -1) {
shoulder.rotation.x = -0.55;
shoulder.rotation.z = -0.25;
elbow.rotation.x = -0.65;
}
return { shoulder, elbow };
}
function buildStanding(parent, character) {
const build = character.build;
cylinder(
parent,
0.25 * build,
0.27 * build,
0.19,
8,
character.pants,
0,
0.79,
0
);
for (const side of [-1, 1]) {
const hip = [side * 0.12 * build, 0.8, 0];
const knee = [
side * 0.135 * build,
0.45,
side < 0 ? 0.035 : -0.025
];
const ankle = [
side * 0.145 * build,
0.105,
side < 0 ? 0.075 : 0.005
];
rod(parent, hip, knee, 0.094 * build, character.pants);
rod(parent, knee, ankle, 0.078 * build, character.pants);
const shoe = box(
parent,
0.19,
0.13,
0.31,
character.shoes,
ankle[0],
0.065,
ankle[2] + 0.065
);
shoe.rotation.y = side < 0 ? -0.06 : 0.07;
}
dressTorso(parent, character, 1.08);
addArm(parent, character, -1);
addArm(parent, character, 1);
cylinder(
parent,
0.073,
0.078,
0.13,
8,
character.skin,
0,
1.38,
0
);
const headPivot = new THREE.Group();
headPivot.position.set(0, 1.56, 0);
parent.add(headPivot);
sphere(
headPivot,
0.23,
character.skin,
0,
0,
0,
0.95,
1.08,
0.94
);
addHair(headPivot, character);
addFace(headPivot, character);
return headPivot;
}
function buildSeated(parent, character) {
const build = character.build;
cylinder(
parent,
0.24 * build,
0.26 * build,
0.2,
8,
character.pants,
0,
0.72,
0.02
);
for (const side of [-1, 1]) {
const hip = [side * 0.12 * build, 0.73, 0.04];
const knee = [side * 0.16 * build, 0.59, 0.31];
const ankle = [side * 0.16 * build, 0.27, 0.38];
rod(parent, hip, knee, 0.09 * build, character.pants);
rod(parent, knee, ankle, 0.075 * build, character.pants);
box(
parent,
0.19,
0.13,
0.29,
character.shoes,
ankle[0],
0.19,
0.45
);
}
dressTorso(parent, character, 0.95);
for (const side of [-1, 1]) {
const shoulder = [side * 0.3 * build, 1.13, 0];
const elbow = [side * 0.34 * build, 0.87, 0.16];
const hand = [side * 0.35 * build, 0.65, 0.19];
rod(parent, shoulder, elbow, 0.071, character.sleeve);
rod(parent, elbow, hand, 0.058, character.sleeve);
sphere(parent, 0.064, character.skin, ...hand);
}
cylinder(
parent,
0.073,
0.078,
0.13,
8,
character.skin,
0,
1.25,
0
);
const headPivot = new THREE.Group();
headPivot.position.set(0, 1.44, 0);
parent.add(headPivot);
sphere(
headPivot,
0.23,
character.skin,
0,
0,
0,
0.95,
1.08,
0.94
);
addHair(headPivot, character);
addFace(headPivot, character);
return headPivot;
}
function addWheelchair(root) {
const wheelchair = new THREE.Group();
root.add(wheelchair);
const frame = 0x344448;
for (const side of [-1, 1]) {
const wheelX = side * 0.36;
const tire = mesh(
new THREE.TorusGeometry(0.31, 0.034, 6, 22),
0x252c2d,
wheelchair,
wheelX,
0.34,
-0.09
);
tire.rotation.y = Math.PI / 2;
const rim = mesh(
new THREE.TorusGeometry(0.265, 0.012, 5, 20),
0xb6bab4,
wheelchair,
wheelX,
0.34,
-0.09
);
rim.rotation.y = Math.PI / 2;
const handRim = mesh(
new THREE.TorusGeometry(0.245, 0.015, 5, 20),
0xd1a34d,
wheelchair,
wheelX + side * 0.075,
0.34,
-0.09
);
handRim.rotation.y = Math.PI / 2;
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
rod(
wheelchair,
[wheelX, 0.34, -0.09],
[
wheelX,
0.34 + Math.sin(angle) * 0.265,
-0.09 + Math.cos(angle) * 0.265
],
0.006,
0xc2c6c0
);
}
const hub = cylinder(
wheelchair,
0.045,
0.045,
0.11,
8,
0x8f9691,
wheelX,
0.34,
-0.09
);
hub.rotation.z = Math.PI / 2;
rod(
wheelchair,
[side * 0.25, 0.55, -0.22],
[side * 0.25, 0.98, -0.28],
0.025,
frame
);
rod(
wheelchair,
[side * 0.25, 0.98, -0.28],
[side * 0.25, 1.12, -0.37],
0.025,
frame
);
rod(
wheelchair,
[side * 0.25, 0.12, 0.35],
[side * 0.25, 0.55, -0.2],
0.022,
frame
);
rod(
wheelchair,
[side * 0.25, 0.55, -0.2],
[side * 0.25, 0.55, 0.24],
0.022,
frame
);
const caster = mesh(
new THREE.TorusGeometry(0.09, 0.022, 5, 14),
0x303839,
wheelchair,
side * 0.25,
0.105,
0.39
);
caster.rotation.y = Math.PI / 2;
}
box(wheelchair, 0.54, 0.075, 0.5, 0x465b5b, 0, 0.56, 0.02);
box(wheelchair, 0.53, 0.45, 0.065, 0x465b5b, 0, 0.82, -0.26);
box(wheelchair, 0.48, 0.045, 0.28, 0x3e5151, 0, 0.2, 0.43);
rod(
wheelchair,
[-0.25, 0.55, 0.2],
[-0.25, 0.2, 0.42],
0.018,
frame
);
rod(
wheelchair,
[0.25, 0.55, 0.2],
[0.25, 0.2, 0.42],
0.018,
frame
);
}
function makeCharacterLabel(character) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 160;
const context = labelCanvas.getContext("2d");
context.fillStyle = "rgba(255,250,240,0.96)";
roundedRect(context, 8, 8, 496, 144, 28);
context.fill();
context.strokeStyle = `#${character.accent.toString(16).padStart(6, "0")}`;
context.lineWidth = 9;
roundedRect(context, 8, 8, 496, 144, 28);
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#263238";
context.font = "750 48px system-ui, sans-serif";
context.fillText(character.shortName, 256, 60);
context.fillStyle = "#6b7476";
context.font = "500 29px system-ui, sans-serif";
context.fillText(`Age ${character.age}`, 256, 112);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: canvasTexture(labelCanvas),
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.78, 0.56, 1);
sprite.position.set(0, character.height + 0.34, 0);
sprite.renderOrder = 20;
return sprite;
}
for (let index = 0; index < cast.length; index++) {
const character = cast[index];
const root = new THREE.Group();
root.position.set(character.x, 0, character.z);
root.userData.castId = character.id;
scene.add(root);
const platform = cylinder(
root,
0.83,
0.86,
0.035,
24,
material(character.accent, {
transparent: true,
opacity: 0.52,
depthWrite: false
}),
0,
-0.012,
0
);
platform.receiveShadow = false;
const ringMaterial = new THREE.MeshBasicMaterial({
color: character.accent,
transparent: true,
opacity: 0.25,
depthWrite: false
});
const ring = mesh(
new THREE.TorusGeometry(0.9, 0.025, 6, 36),
ringMaterial,
root,
0,
0.018,
0
);
ring.rotation.x = Math.PI / 2;
ring.castShadow = false;
root.userData.ring = ring;
const actor = new THREE.Group();
actor.scale.setScalar(character.height / 1.8);
root.add(actor);
const headPivot = character.seated
? buildSeated(actor, character)
: buildStanding(actor, character);
root.userData.headPivot = headPivot;
if (character.seated) {
addWheelchair(root);
}
const label = makeCharacterLabel(character);
root.add(label);
const pickMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
colorWrite: false
});
const pick = mesh(
new THREE.SphereGeometry(0.55, 8, 6),
pickMaterial,
root,
0,
character.height * 0.58,
0
);
pick.scale.y = character.height / 0.9;
pick.castShadow = false;
pick.receiveShadow = false;
pick.userData.castId = character.id;
pickMeshes.push(pick);
characters.push({ root, actor, headPivot, character });
}
// -------------------------------------------------------------------------
// Interest-related props
// -------------------------------------------------------------------------
function makeMapBoard() {
const group = new THREE.Group();
group.position.set(-5.75, 0, 0.82);
group.rotation.y = 0.2;
scene.add(group);
rod(group, [-0.36, 0.04, 0], [-0.36, 1.45, 0], 0.035, 0x785a43);
rod(group, [0.36, 0.04, 0], [0.36, 1.45, 0], 0.035, 0x785a43);
rod(group, [-0.46, 0.12, 0], [0.46, 0.12, 0], 0.03, 0x785a43);
box(group, 1.1, 0.78, 0.08, 0x5a493d, 0, 1.12, 0);
const mapCanvas = document.createElement("canvas");
mapCanvas.width = 512;
mapCanvas.height = 360;
const ctx = mapCanvas.getContext("2d");
ctx.fillStyle = "#eee0bd";
ctx.fillRect(0, 0, 512, 360);
ctx.strokeStyle = "#c6b88f";
ctx.lineWidth = 18;
for (let x = 0; x <= 512; x += 85) {
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x + 25, 360);
ctx.stroke();
}
for (let y = 0; y <= 360; y += 72) {
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(512, y - 12);
ctx.stroke();
}
ctx.strokeStyle = "#478d9c";
ctx.lineWidth = 18;
ctx.beginPath();
ctx.moveTo(-10, 282);
ctx.bezierCurveTo(140, 210, 315, 280, 530, 155);
ctx.stroke();
ctx.fillStyle = "#d95f45";
for (const [x, y] of [[92, 105], [268, 210], [398, 91]]) {
ctx.beginPath();
ctx.arc(x, y, 13, 0, Math.PI * 2);
ctx.fill();
}
ctx.fillStyle = "#35474a";
ctx.font = "700 28px system-ui, sans-serif";
ctx.fillText("NEIGHBORHOOD / 04", 25, 42);
const map = mesh(
new THREE.PlaneGeometry(0.98, 0.68),
new THREE.MeshBasicMaterial({ map: canvasTexture(mapCanvas) }),
group,
0,
1.12,
0.046
);
map.castShadow = false;
}
function makeRadioKit() {
const group = new THREE.Group();
group.position.set(-1.3, 0, 0.65);
group.rotation.y = -0.15;
scene.add(group);
box(group, 0.58, 0.36, 0.38, 0x506d72, 0, 0.22, 0);
box(group, 0.5, 0.28, 0.025, 0x283a3f, 0, 0.23, 0.205);
rod(group, [0.18, 0.4, 0], [0.18, 0.92, -0.02], 0.012, 0x30393a);
sphere(group, 0.04, 0xe0b852, -0.15, 0.27, 0.225);
cylinder(group, 0.045, 0.045, 0.025, 8, 0xd96b50, 0.13, 0.2, 0.225);
}
function makeBicycle() {
const group = new THREE.Group();
group.position.set(1.05, 0, -1.25);
group.rotation.y = -0.3;
scene.add(group);
const tire = 0x2e3536;
const metal = 0x4f9c8f;
for (const x of [-0.66, 0.66]) {
const wheel = mesh(
new THREE.TorusGeometry(0.4, 0.026, 6, 22),
tire,
group,
x,
0.42,
0
);
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
rod(
group,
[x, 0.42, 0],
[x, 0.42 + Math.sin(angle) * 0.37, Math.cos(angle) * 0.37],
0.006,
0xa8aaa5
);
}
}
const points = {
rear: [-0.66, 0.42, 0],
front: [0.66, 0.42, 0],
crank: [-0.08, 0.42, 0],
seat: [-0.3, 0.88, 0],
head: [0.43, 0.88, 0]
};
for (const [a, b] of [
["rear", "crank"],
["crank", "seat"],
["seat", "rear"],
["seat", "head"],
["head", "crank"],
["head", "front"]
]) {
rod(group, points[a], points[b], 0.022, metal);
}
rod(group, [-0.38, 0.91, 0], [-0.18, 0.91, 0], 0.025, 0x303638);
box(group, 0.28, 0.06, 0.18, 0x303638, -0.31, 0.95, 0);
rod(group, [0.43, 0.88, 0], [0.5, 1.05, 0], 0.02, 0x303638);
rod(group, [0.4, 1.06, -0.18], [0.6, 1.06, 0.18], 0.018, 0x303638);
}
function makeProjector() {
const group = new THREE.Group();
group.position.set(3.55, 0, 0.73);
scene.add(group);
cylinder(group, 0.44, 0.5, 0.08, 10, 0x775d45, 0, 0.48, 0);
rod(group, [0, 0.5, 0], [0, 0.83, 0], 0.035, 0x4b5654);
box(group, 0.46, 0.28, 0.36, 0x4b5654, 0, 0.98, 0);
cylinder(group, 0.085, 0.085, 0.18, 10, 0x273336, 0, 0.98, 0.25);
rod(group, [0.08, 0.98, 0], [0.16, 1.34, 0], 0.012, 0x30393a);
}
function makePlanter() {
const group = new THREE.Group();
group.position.set(5.72, 0, 1.08);
scene.add(group);
cylinder(group, 0.39, 0.31, 0.58, 7, 0xa56848, 0, 0.28, 0);
cylinder(group, 0.34, 0.34, 0.06, 7, 0x544333, 0, 0.59, 0);
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
rod(
group,
[0, 0.61, 0],
[
Math.cos(angle) * 0.24,
0.95 + (i % 2) * 0.15,
Math.sin(angle) * 0.24
],
0.017,
0x4f7d53
);
icosahedron(
group,
0.13,
i % 2 ? 0x75a465 : 0x9ab46d,
Math.cos(angle) * 0.25,
1.0 + (i % 2) * 0.15,
Math.sin(angle) * 0.25,
1
);
}
}
makeMapBoard();
makeRadioKit();
makeBicycle();
makeProjector();
makePlanter();
// A small recorder beside Tavi.
const recorder = new THREE.Group();
recorder.position.set(5.05, 0.04, 1.65);
recorder.rotation.y = -0.35;
scene.add(recorder);
box(recorder, 0.22, 0.13, 0.13, 0x465b5c, 0, 0.065, 0);
cylinder(recorder, 0.045, 0.045, 0.04, 10, 0x222d2e, -0.05, 0.15, 0);
// -------------------------------------------------------------------------
// UI and character selection
// -------------------------------------------------------------------------
const buttons = new Map();
for (const character of cast) {
const button = document.createElement("button");
button.type = "button";
button.textContent = `${character.shortName} · ${character.age}`;
button.style.setProperty(
"--button-accent",
`#${character.accent.toString(16).padStart(6, "0")}`
);
button.setAttribute("aria-pressed", "false");
button.addEventListener("click", () => selectCharacter(character.id, true));
castNav.append(button);
buttons.set(character.id, button);
}
const resetButton = document.createElement("button");
resetButton.type = "button";
resetButton.className = "reset";
resetButton.textContent = "Whole cast";
resetButton.addEventListener("click", resetView);
castNav.append(resetButton);
// Custom camera controls; no examples/addons are used.
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
const goalTarget = cameraTarget.clone();
let cameraDistance = 15.5;
let goalDistance = cameraDistance;
let cameraAzimuth = 0.19;
let goalAzimuth = cameraAzimuth;
let cameraPolar = 1.18;
let goalPolar = cameraPolar;
let selectedId = null;
function selectCharacter(id, moveCamera = true) {
const character = cast.find((entry) => entry.id === id);
if (!character) return;
selectedId = id;
for (const entry of characters) {
const active = entry.character.id === id;
entry.root.userData.ring.material.opacity = active ? 0.92 : 0.2;
entry.root.userData.ring.scale.setScalar(active ? 1.05 : 1);
}
for (const [buttonId, button] of buttons) {
button.setAttribute("aria-pressed", String(buttonId === id));
}
profile.innerHTML = `
<p class="eyebrow">${character.age} · ${character.pronouns}</p>
<h2>${character.name}</h2>
<p class="meta">${character.height.toFixed(2)} m tall · ${character.pronouns}</p>
<p class="bio">${character.bio}</p>
<p class="detail"><strong>Scene detail:</strong> ${character.detail}</p>
<p class="principle">
Age, build, and mobility aids are descriptive details, not shorthand
for personality or capability. Each person's interests and skills are
presented independently.
</p>
`;
if (moveCamera) {
goalTarget.set(character.x, character.height * 0.57, character.z);
goalDistance = Math.max(4.25, character.height * 2.55);
}
}
function resetView() {
selectedId = null;
goalTarget.set(0, 1.35, 0);
goalDistance = 15.5;
goalAzimuth = 0.19;
goalPolar = 1.18;
for (const entry of characters) {
entry.root.userData.ring.material.opacity = 0.2;
entry.root.userData.ring.scale.setScalar(1);
}
for (const button of buttons.values()) {
button.setAttribute("aria-pressed", "false");
}
resetButton.setAttribute("aria-pressed", "true");
profile.innerHTML = `
<p class="eyebrow">Meet the cast</p>
<h2>Common Ground</h2>
<p class="meta">Select a neighbor to learn more.</p>
<p class="bio">
The plaza is a place for maps, radio signals, bicycles, film, plants,
and conversation.
</p>
<p class="detail">
<strong>Camera:</strong> drag to orbit, scroll or pinch to zoom.
Arrow keys rotate; + and − zoom; R resets the view.
</p>
<p class="principle">
Age, build, and mobility aids are descriptive details, not shorthand
for personality or capability. Each person's interests and skills are
presented independently.
</p>
`;
}
function updateCamera(dt) {
const smoothing = reducedMotion ? 1 : 1 - Math.exp(-6.5 * dt);
cameraTarget.lerp(goalTarget, smoothing);
cameraDistance += (goalDistance - cameraDistance) * smoothing;
cameraAzimuth += (goalAzimuth - cameraAzimuth) * smoothing;
cameraPolar += (goalPolar - cameraPolar) * smoothing;
const horizontal = Math.sin(cameraPolar) * cameraDistance;
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraAzimuth),
cameraTarget.y + Math.cos(cameraPolar) * cameraDistance,
cameraTarget.z + horizontal * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Pointer, wheel, touch, and keyboard controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let dragging = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
let dragDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
dragDistance = 0;
canvas.setPointerCapture(pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
goalAzimuth -= dx * 0.006;
goalPolar = THREE.MathUtils.clamp(goalPolar + dy * 0.005, 0.48, 1.46);
});
function endPointer(event) {
if (!dragging || event.pointerId !== pointerId) return;
dragging = false;
if (dragDistance < 7) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
if (hits.length) {
selectCharacter(hits[0].object.userData.castId, true);
}
}
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
goalDistance = THREE.MathUtils.clamp(
goalDistance + event.deltaY * 0.012,
3.5,
24
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLButtonElement) return;
const key = event.key.toLowerCase();
if (key === "arrowleft") {
goalAzimuth += 0.12;
event.preventDefault();
} else if (key === "arrowright") {
goalAzimuth -= 0.12;
event.preventDefault();
} else if (key === "arrowup") {
goalPolar = THREE.MathUtils.clamp(goalPolar - 0.09, 0.48, 1.46);
event.preventDefault();
} else if (key === "arrowdown") {
goalPolar = THREE.MathUtils.clamp(goalPolar + 0.09, 0.48, 1.46);
event.preventDefault();
} else if (key === "+" || key === "=") {
goalDistance = THREE.MathUtils.clamp(goalDistance - 0.7, 3.5, 24);
event.preventDefault();
} else if (key === "-" || key === "_") {
goalDistance = THREE.MathUtils.clamp(goalDistance + 0.7, 3.5, 24);
event.preventDefault();
} else if (key === "r") {
resetView();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.setSize(innerWidth, innerHeight);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
let previousTime = performance.now();
function animate(time) {
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
const elapsed = time * 0.001;
updateCamera(dt);
if (!reducedMotion) {
for (let i = 0; i < characters.length; i++) {
const character = characters[i];
character.headPivot.rotation.y =
Math.sin(elapsed * 0.55 + i * 1.7) * 0.055;
character.actor.position.y =
Math.sin(elapsed * 0.9 + i) * 0.004;
}
for (const character of characters) {
if (character.character.id === selectedId) {
character.root.userData.ring.material.opacity =
0.78 + Math.sin(elapsed * 2.1) * 0.14;
}
}
}
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```