Prompt specification
Build or customize the Three.js 3D scene "Town Square Cast With Distinct Silhouettes" 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: Town Square Cast With Distinct Silhouettes
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/town-square-cast-with-distinct-silhouettes-x3699
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing character body proportions and recognizable silhouettes. Build a small original town-square scene containing varied body shapes, clothing, and roles. Make characters distinguishable by geometry rather than attaching personality stereotypes to appearance. Voxel style.
Working Three.js Starter (town-square-cast-with-distinct-silhouettes-x3699):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cubehaven Commons — Voxel Character Scene</title>
<style>
:root {
color-scheme: dark;
--ink: #17212b;
--panel: rgba(19, 29, 38, 0.88);
--panel-edge: rgba(255, 255, 255, 0.14);
--paper: #f3eee2;
--muted: #b9c4c9;
--accent: #efbd66;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b9d7d8;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.title-card {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 17px 19px 16px;
color: var(--paper);
background: var(--panel);
border: 1px solid var(--panel-edge);
border-radius: 14px;
box-shadow: 0 14px 40px rgba(18, 30, 40, 0.2);
backdrop-filter: blur(12px);
user-select: none;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 31px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.toolbar {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 13px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 8px;
padding: 8px 10px;
color: var(--paper);
background: rgba(255, 255, 255, 0.08);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 140ms ease, transform 140ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.16);
transform: translateY(-1px);
}
button.active {
color: #17212b;
background: var(--accent);
}
.roster {
position: fixed;
z-index: 10;
top: 20px;
right: 20px;
width: 315px;
max-height: calc(100vh - 40px);
overflow: auto;
padding: 16px;
color: var(--paper);
background: var(--panel);
border: 1px solid var(--panel-edge);
border-radius: 14px;
box-shadow: 0 14px 40px rgba(18, 30, 40, 0.2);
backdrop-filter: blur(12px);
scrollbar-width: thin;
scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}
.roster-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.roster-heading strong {
font-size: 13px;
letter-spacing: 0.02em;
}
.roster-heading span {
color: var(--muted);
font-size: 10px;
}
.note {
margin: 0 0 12px;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
#roster-list {
display: grid;
gap: 7px;
}
.character-card {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
align-items: center;
padding: 8px;
border: 1px solid transparent;
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease;
}
.character-card:hover,
.character-card.selected {
background: rgba(239, 189, 102, 0.11);
border-color: rgba(239, 189, 102, 0.5);
}
.mini {
display: flex;
width: 27px;
height: 46px;
flex-direction: column;
align-items: center;
justify-content: flex-end;
}
.mini i,
.mini b,
.mini em {
display: block;
flex: 0 0 auto;
border-radius: 1px;
}
.mini i {
width: 6px;
height: var(--leg);
background: #80a9b5;
}
.mini b {
width: var(--wide);
max-width: 23px;
height: var(--torso);
background: var(--accent);
}
.mini em {
width: 10px;
height: var(--head);
background: #e3b695;
}
.card-name {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
}
.card-name strong {
font-size: 11.5px;
}
.card-name span {
color: var(--accent);
font-size: 9px;
font-weight: 800;
text-transform: uppercase;
}
.card-cue {
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
.callout {
position: fixed;
z-index: 8;
min-width: 92px;
padding: 5px 8px 6px;
color: #17212b;
background: rgba(255, 250, 235, 0.92);
border: 1px solid rgba(23, 33, 43, 0.22);
border-radius: 7px;
box-shadow: 0 5px 18px rgba(23, 33, 43, 0.16);
text-align: center;
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 120ms ease, background 120ms ease;
}
.callout::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 13px;
background: rgba(23, 33, 43, 0.4);
}
.callout span {
display: block;
font-size: 9px;
font-weight: 900;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.callout b {
display: block;
margin-top: 1px;
color: #52616b;
font-size: 8.5px;
font-weight: 650;
}
.callout.selected {
background: var(--accent);
}
.hint {
position: fixed;
z-index: 9;
left: 20px;
bottom: 18px;
max-width: calc(100vw - 40px);
padding: 8px 11px;
color: rgba(255, 255, 255, 0.88);
background: rgba(23, 33, 43, 0.72);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
font-size: 10.5px;
pointer-events: none;
backdrop-filter: blur(8px);
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
color: var(--paper);
background: #263744;
font-size: 13px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
.title-card {
top: 12px;
left: 12px;
width: min(340px, calc(100vw - 24px));
padding: 13px 15px;
}
.roster {
top: auto;
right: 12px;
bottom: 12px;
width: min(300px, calc(100vw - 24px));
max-height: 37vh;
padding: 12px;
}
.hint {
display: none;
}
.subtitle {
display: none;
}
.callout {
transform: translate(-50%, -100%) scale(0.88);
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="title-card">
<div class="eyebrow">Original voxel environment</div>
<h1>Cubehaven Commons</h1>
<p class="subtitle">
Eight civic silhouettes, built from proportion, clothing shapes, and
role-specific tools.
</p>
<div class="toolbar">
<button id="reset-view" type="button">Reset view</button>
<button id="toggle-labels" class="active" type="button">Callouts</button>
<button id="toggle-dusk" type="button">Dusk</button>
</div>
</header>
<aside class="roster" aria-label="Character roster and body proportions">
<div class="roster-heading">
<strong>Commons roster</strong>
<span>proportion / silhouette cue</span>
</div>
<p class="note">
Roles are communicated through carried objects and garment geometry.
Appearance is not used to imply personality.
</p>
<div id="roster-list"></div>
</aside>
<div class="hint">
Drag to orbit · wheel/pinch to zoom · right-drag to pan · arrow keys to rotate ·
R to reset
</div>
<div id="loading">Building Cubehaven…</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 stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel town square with varied character silhouettes"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
const dayColor = new THREE.Color(0xb9d7d8);
const duskColor = new THREE.Color(0x27344b);
scene.background = dayColor.clone();
scene.fog = new THREE.Fog(dayColor.clone(), 31, 61);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xdff4ff, 0x6f5947, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d0, 3.1);
sun.position.set(-9, 15, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -17;
sun.shadow.camera.right = 17;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x91bdd5, 0.65);
fillLight.position.set(11, 7, -10);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Reusable voxel geometry helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
const geometryCache = new Map();
function material(color) {
if (color && color.isMaterial) return color;
const key = String(color);
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.83,
metalness: 0.02
})
);
}
return materialCache.get(key);
}
function boxGeometry(x, y, z) {
const key = `${x}|${y}|${z}`;
if (!geometryCache.has(key)) {
geometryCache.set(key, new THREE.BoxGeometry(x, y, z));
}
return geometryCache.get(key);
}
function box(
parent,
size,
position,
color,
rotation = [0, 0, 0],
shadow = true
) {
const mesh = new THREE.Mesh(
boxGeometry(size[0], size[1], size[2]),
material(color)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.rotation.set(rotation[0], rotation[1], rotation[2]);
mesh.castShadow = shadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function seededRandom(seed) {
return function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(8417);
// -------------------------------------------------------------------------
// Town square ground and paving
// -------------------------------------------------------------------------
const world = new THREE.Group();
scene.add(world);
box(world, [27, 0.45, 27], [0, -0.27, 0], 0x78965d, [0, 0, 0], false);
box(world, [23.2, 0.18, 23.2], [0, -0.08, 0], 0x8d7967, [0, 0, 0], false);
const tileCount = 14;
const tileStep = 1.58;
const tileSize = 1.48;
const tileGeometry = new THREE.BoxGeometry(tileSize, 0.12, tileSize);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCount * tileCount
);
tiles.receiveShadow = true;
const tileColors = [
new THREE.Color(0xc5b7a0),
new THREE.Color(0xb7aa96),
new THREE.Color(0xd0c2aa),
new THREE.Color(0xa9a293),
new THREE.Color(0xbeb39f)
];
const dummy = new THREE.Object3D();
let tileIndex = 0;
for (let row = 0; row < tileCount; row++) {
for (let col = 0; col < tileCount; col++) {
const x = (col - (tileCount - 1) / 2) * tileStep;
const z = (row - (tileCount - 1) / 2) * tileStep;
dummy.position.set(x, 0.025, z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
tiles.setColorAt(
tileIndex,
tileColors[Math.floor(random() * tileColors.length)]
);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
world.add(tiles);
// A darker geometric border makes the square read clearly from above.
for (const side of [-1, 1]) {
box(world, [22.6, 0.025, 0.16], [0, 0.095, side * 10.95], 0x837968, [0, 0, 0], false);
box(world, [0.16, 0.025, 22.6], [side * 10.95, 0.095, 0], 0x837968, [0, 0, 0], false);
}
// -------------------------------------------------------------------------
// Architecture
// -------------------------------------------------------------------------
const windowMaterial = new THREE.MeshStandardMaterial({
color: 0x536e78,
emissive: 0xffb65c,
emissiveIntensity: 0.25,
roughness: 0.45
});
const doorMaterial = new THREE.MeshStandardMaterial({
color: 0x493b35,
roughness: 0.9
});
function makeBuilding({
x,
z,
rotation = 0,
width = 5,
depth = 4,
height = 5,
wall = 0xb78367,
roof = 0x4d6570,
sign = 0xe4c58f
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(group, [width, height, depth], [0, height / 2, 0], wall);
box(group, [width + 0.18, 0.24, depth + 0.18], [0, 0.12, 0], 0x827363);
// Stepped voxel roof.
const roofLayers = 4;
for (let i = 0; i < roofLayers; i++) {
const layerWidth = width + 0.55 - i * (width / 5.3);
const layerDepth = depth + 0.55 - i * (depth / 6.1);
box(
group,
[layerWidth, 0.34, layerDepth],
[0, height + 0.22 + i * 0.31, 0],
i % 2 === 0 ? roof : new THREE.Color(roof).offsetHSL(0, 0, 0.035).getHex()
);
}
// Front windows.
const windowRows = height > 5 ? 2 : 1;
for (let row = 0; row < windowRows; row++) {
for (let col = -1; col <= 1; col += 2) {
const wx = col * width * 0.25;
const wy = 1.75 + row * 1.8;
box(group, [0.76, 1.05, 0.08], [wx, wy, depth / 2 + 0.055], windowMaterial);
box(group, [0.92, 0.12, 0.15], [wx, wy - 0.56, depth / 2 + 0.09], sign);
box(group, [0.08, 1.08, 0.14], [wx, wy, depth / 2 + 0.09], sign);
}
}
// Central door and awning.
box(group, [1.12, 2.05, 0.13], [0, 1.025, depth / 2 + 0.07], doorMaterial);
box(group, [1.55, 0.16, 0.72], [0, 2.2, depth / 2 + 0.29], sign);
box(group, [0.08, 0.55, 0.09], [0.34, 1.13, depth / 2 + 0.15], 0xe8c66d);
return group;
}
makeBuilding({
x: -6.1,
z: -9.55,
width: 5.1,
depth: 4.1,
height: 5.15,
wall: 0xb47e64,
roof: 0x4b6670
});
makeBuilding({
x: 0.2,
z: -10.05,
width: 5.6,
depth: 4.1,
height: 5.65,
wall: 0xc19a70,
roof: 0x6b5368
});
makeBuilding({
x: 6.55,
z: -9.45,
width: 4.9,
depth: 4.2,
height: 4.65,
wall: 0x809282,
roof: 0x445c67
});
makeBuilding({
x: -10.1,
z: -3.6,
rotation: Math.PI / 2,
width: 5.3,
depth: 4.2,
height: 4.75,
wall: 0x9f7b70,
roof: 0x536870
});
makeBuilding({
x: 10.15,
z: -3.15,
rotation: -Math.PI / 2,
width: 5.4,
depth: 4.1,
height: 5.0,
wall: 0xb49a72,
roof: 0x5a596c
});
// -------------------------------------------------------------------------
// Fountain, planters, trees, lamps, and stall
// -------------------------------------------------------------------------
const fountain = new THREE.Group();
fountain.position.set(0, 0, -2.25);
world.add(fountain);
box(fountain, [5.4, 0.28, 5.4], [0, 0.15, 0], 0x7c756c);
box(fountain, [4.55, 0.55, 4.55], [0, 0.4, 0], 0xa49a88);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x5fc0d4,
emissive: 0x164e60,
emissiveIntensity: 0.22,
transparent: true,
opacity: 0.84,
roughness: 0.22
});
const water = box(fountain, [4.05, 0.08, 4.05], [0, 0.55, 0], waterMaterial);
box(fountain, [0.75, 1.25, 0.75], [0, 1.12, 0], 0x9b9180);
box(fountain, [1.5, 0.24, 1.5], [0, 1.82, 0], 0xa99d88);
box(fountain, [0.48, 0.55, 0.48], [0, 2.15, 0], 0xb4a68f);
const waterJets = [];
for (const [x, z] of [
[0.58, 0],
[-0.58, 0],
[0, 0.58],
[0, -0.58]
]) {
waterJets.push(
box(fountain, [0.13, 0.72, 0.13], [x, 2.18, z], waterMaterial)
);
}
function makeTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
world.add(group);
box(group, [0.52, 2.6, 0.52], [0, 1.3, 0], 0x72533e);
box(group, [2.1, 1.25, 1.75], [0, 3.05, 0], 0x587a45);
box(group, [1.45, 1.05, 1.45], [-0.32, 4.0, 0.08], 0x668a4e);
box(group, [1.55, 0.9, 1.25], [0.45, 3.65, -0.18], 0x4e7041);
box(group, [0.9, 0.7, 0.9], [0.05, 4.62, 0], 0x739354);
}
makeTree(-10.2, 6.6, 1.05);
makeTree(10.2, 6.2, 1.08);
makeTree(-10.4, -7.8, 0.88);
makeTree(10.5, -7.9, 0.92);
function makePlanter(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
box(group, [2.15, 0.48, 0.8], [0, 0.24, 0], 0x9b7559);
box(group, [1.95, 0.12, 0.62], [0, 0.53, 0], 0x536c42);
for (let i = -2; i <= 2; i++) {
box(group, [0.28, 0.35 + random() * 0.25, 0.32], [i * 0.34, 0.7, 0], i % 2 ? 0x6d8e50 : 0x7d9c58);
}
}
makePlanter(-3.35, -3.5);
makePlanter(3.35, -3.5);
const lampLights = [];
function makeLamp(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
world.add(group);
box(group, [0.5, 0.22, 0.5], [0, 0.11, 0], 0x4c5556);
box(group, [0.17, 3.8, 0.17], [0, 1.95, 0], 0x37464b);
box(group, [0.92, 0.14, 0.14], [0.32, 3.78, 0], 0x37464b);
box(group, [0.58, 0.68, 0.58], [0.7, 3.35, 0], 0x344147);
box(group, [0.34, 0.4, 0.34], [0.7, 3.35, 0], windowMaterial);
const light = new THREE.PointLight(0xffc66e, 0, 6, 2);
light.position.set(0.7, 3.25, 0);
group.add(light);
lampLights.push(light);
}
makeLamp(-7.7, -1.1);
makeLamp(7.8, -1.1);
makeLamp(-8.2, 5.8);
makeLamp(8.3, 5.8);
function makeBench(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
world.add(group);
box(group, [2.5, 0.18, 0.62], [0, 0.75, 0], 0x856044);
box(group, [2.5, 0.7, 0.14], [0, 1.12, -0.27], 0x956b4b);
box(group, [0.16, 0.75, 0.48], [-0.92, 0.38, 0], 0x4c5550);
box(group, [0.16, 0.75, 0.48], [0.92, 0.38, 0], 0x4c5550);
}
makeBench(-5.5, -2.7, 0.2);
makeBench(5.35, -2.65, -0.15);
const stall = new THREE.Group();
stall.position.set(6.4, 0, -3.4);
stall.rotation.y = -0.12;
world.add(stall);
for (const x of [-1.7, 1.7]) {
for (const z of [-0.85, 0.85]) {
box(stall, [0.14, 2.8, 0.14], [x, 1.4, z], 0x6d523e);
}
}
box(stall, [3.8, 0.24, 1.85], [0, 1.05, 0], 0x9a7049);
box(stall, [3.95, 0.18, 1.95], [0, 2.7, 0], 0xe6d3aa);
const canopyColors = [0xcf6655, 0xe6d3aa, 0x4f7d75, 0xe6d3aa, 0xcf6655];
for (let i = 0; i < 5; i++) {
box(
stall,
[0.82, 0.25, 2.25],
[-1.64 + i * 0.82, 2.98 - (i % 2) * 0.08, 0],
canopyColors[i]
);
}
box(stall, [0.75, 0.48, 0.68], [-1.05, 1.4, 0.15], 0x815b3f);
box(stall, [0.75, 0.48, 0.68], [0, 1.4, 0.15], 0x815b3f);
box(stall, [0.75, 0.48, 0.68], [1.05, 1.4, 0.15], 0x815b3f);
const produceColors = [0xd79a32, 0xb95038, 0x71924c, 0xd5b44c];
for (let i = 0; i < 9; i++) {
box(
stall,
[0.24, 0.24, 0.24],
[-1.3 + (i % 3) * 0.26, 1.75, -0.2 + Math.floor(i / 3) * 0.25],
produceColors[i % produceColors.length]
);
}
// Small overhead block clouds.
const clouds = [];
function makeCloud(x, y, z, scale) {
const group = new THREE.Group();
group.position.set(x, y, z);
group.scale.setScalar(scale);
world.add(group);
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf1f0df,
roughness: 1,
transparent: true,
opacity: 0.9
});
box(group, [2.5, 0.6, 1.0], [0, 0, 0], cloudMaterial, [0, 0, 0], false);
box(group, [1.4, 0.9, 1.1], [-0.65, 0.42, 0], cloudMaterial, [0, 0, 0], false);
box(group, [1.25, 0.8, 0.95], [0.75, 0.36, 0.05], cloudMaterial, [0, 0, 0], false);
clouds.push({ group, speed: 0.12 + random() * 0.08 });
}
makeCloud(-8, 9.8, -8, 1.25);
makeCloud(3, 11.2, -12, 1.0);
makeCloud(10, 9.2, -4, 0.85);
// -------------------------------------------------------------------------
// Character specifications
// -------------------------------------------------------------------------
const specs = [
{
id: "surveyor",
name: "Pell",
role: "Surveyor",
cue: "Tall frame, long coat, brimmed hat, staff and plan",
proportion: "Tall · long legs",
legs: 1.42,
torso: 0.94,
head: 0.58,
shoulder: 0.98,
hip: 0.72,
arm: 1.02,
cloth: 0x416875,
accent: 0xe4bb63,
skin: 0xb97b57,
hair: 0x2c2929,
position: [-5.45, 0, 3.95],
rotation: -0.12
},
{
id: "mason",
name: "Odo",
role: "Mason",
cue: "Compact body, broad shoulders, apron and carried blocks",
proportion: "Compact · broad torso",
legs: 0.76,
torso: 1.08,
head: 0.59,
shoulder: 1.68,
hip: 1.08,
arm: 0.88,
cloth: 0x8b593e,
accent: 0xd8cda6,
skin: 0xe0aa82,
hair: 0x483126,
position: [-2.85, 0, 5.1],
rotation: 0.08
},
{
id: "vendor",
name: "Rhea",
role: "Greengrocer",
cue: "Layered skirt, apron, square produce basket",
proportion: "Medium · tapered lower body",
legs: 0.92,
torso: 0.88,
head: 0.58,
shoulder: 1.08,
hip: 0.82,
arm: 0.94,
cloth: 0x6d4b73,
accent: 0xe4a16b,
skin: 0x8d5a40,
hair: 0x271f22,
position: [0.05, 0, 5.25],
rotation: -0.02
},
{
id: "courier",
name: "Tavi",
role: "Courier",
cue: "Small body, large satchel, diagonal strap and cap",
proportion: "Short · compact limbs",
legs: 0.66,
torso: 0.79,
head: 0.55,
shoulder: 0.91,
hip: 0.72,
arm: 0.77,
cloth: 0xb65d43,
accent: 0xf0d49a,
skin: 0xdca57e,
hair: 0x33251f,
position: [2.75, 0, 4.72],
rotation: 0.1
},
{
id: "fiddler",
name: "Iven",
role: "Fiddler",
cue: "Narrow torso, geometric string instrument and bow",
proportion: "Medium · narrow frame",
legs: 1.04,
torso: 1.08,
head: 0.56,
shoulder: 0.98,
hip: 0.72,
arm: 1.02,
cloth: 0x356b5a,
accent: 0xd7a64a,
skin: 0x704631,
hair: 0x202126,
position: [5.42, 0, 3.35],
rotation: -0.18
},
{
id: "planter",
name: "Sera",
role: "Planter",
cue: "Wide hat, apron, trowel and seedling crate",
proportion: "Stocky · low center",
legs: 0.83,
torso: 0.93,
head: 0.58,
shoulder: 1.24,
hip: 0.91,
arm: 0.9,
cloth: 0x557747,
accent: 0xc98455,
skin: 0xc58b68,
hair: 0x4a3024,
position: [-6.78, 0, 0.65],
rotation: 0.38
},
{
id: "lampkeeper",
name: "Lio",
role: "Lampkeeper",
cue: "Very tall frame, long pole and suspended square lantern",
proportion: "Very tall · elongated legs",
legs: 1.58,
torso: 0.79,
head: 0.55,
shoulder: 0.91,
hip: 0.69,
arm: 1.08,
cloth: 0x465b78,
accent: 0xf0c46b,
skin: 0x9e684c,
hair: 0x24242b,
position: [4.75, 0, -0.45],
rotation: -0.42
},
{
id: "scribe",
name: "Emet",
role: "Archivist",
cue: "Square book stack, large folio and high collar",
proportion: "Average · upright torso",
legs: 0.97,
torso: 0.98,
head: 0.67,
shoulder: 1.22,
hip: 0.83,
arm: 0.94,
cloth: 0x6b526f,
accent: 0xd7c48c,
skin: 0xefc3a0,
hair: 0x5a3d35,
position: [-2.35, 0, -0.65],
rotation: 0.28
}
];
const figures = [];
const pickables = [];
// -------------------------------------------------------------------------
// Voxel character construction
// -------------------------------------------------------------------------
function makeCharacter(spec) {
const group = new THREE.Group();
group.position.set(...spec.position);
group.rotation.y = spec.rotation;
const shoeY = 0.1;
const legBottom = 0.19;
const legCenter = legBottom + spec.legs / 2;
const torsoBottom = legBottom + spec.legs + 0.12;
const torsoTop = torsoBottom + spec.torso;
const torsoCenter = (torsoBottom + torsoTop) / 2;
const headBottom = torsoTop + 0.1;
const headCenter = headBottom + spec.head / 2;
const headTop = headBottom + spec.head;
const shoulderY = torsoTop - 0.08;
const waistY = torsoBottom + 0.1;
const armLength = spec.arm;
const shoulderX = spec.shoulder / 2 + 0.1;
// Shoes and legs.
box(group, [0.34, 0.2, 0.49], [-spec.hip * 0.27, shoeY, 0.08], 0x3e3835);
box(group, [0.34, 0.2, 0.49], [spec.hip * 0.27, shoeY, 0.08], 0x3e3835);
box(
group,
[0.27, spec.legs, 0.33],
[-spec.hip * 0.27, legCenter, 0],
spec.id === "vendor" ? 0x493947 : spec.cloth
);
box(
group,
[0.27, spec.legs, 0.33],
[spec.hip * 0.27, legCenter, 0],
spec.id === "vendor" ? 0x493947 : spec.cloth
);
// Hips, torso, collar.
box(group, [spec.hip, 0.22, 0.46], [0, torsoBottom - 0.05, 0], spec.cloth);
box(
group,
[spec.shoulder, spec.torso, 0.56],
[0, torsoCenter, 0],
spec.cloth
);
box(
group,
[spec.shoulder * 0.57, 0.13, 0.62],
[0, torsoTop + 0.02, 0],
spec.accent
);
// Belt.
box(
group,
[spec.shoulder + 0.02, 0.11, 0.59],
[0, waistY, 0],
0x3f3934
);
// Arms are pivoted from the shoulders.
const armL = new THREE.Group();
const armR = new THREE.Group();
armL.position.set(-shoulderX, shoulderY, 0);
armR.position.set(shoulderX, shoulderY, 0);
group.add(armL, armR);
for (const arm of [armL, armR]) {
box(
arm,
[0.24, armLength, 0.31],
[0, -armLength / 2, 0],
spec.cloth
);
box(
arm,
[0.26, 0.25, 0.3],
[0, -armLength - 0.06, 0],
spec.skin
);
}
// Neck and head.
box(group, [0.26, 0.16, 0.26], [0, torsoTop + 0.07, 0], spec.skin);
box(
group,
[spec.head, spec.head, spec.head],
[0, headCenter, 0],
spec.skin
);
// Simple, neutral face geometry.
box(
group,
[0.055, 0.065, 0.035],
[-spec.head * 0.19, headCenter + 0.05, spec.head / 2 + 0.018],
0x272526
);
box(
group,
[0.055, 0.065, 0.035],
[spec.head * 0.19, headCenter + 0.05, spec.head / 2 + 0.018],
0x272526
);
box(
group,
[0.065, 0.08, 0.055],
[0, headCenter - 0.015, spec.head / 2 + 0.035],
spec.skin
);
box(
group,
[0.17, 0.025, 0.028],
[0, headCenter - spec.head * 0.18, spec.head / 2 + 0.022],
0x744c43
);
// Hair cap, omitted or replaced where a role hat is used.
if (!["surveyor", "planter", "courier"].includes(spec.id)) {
box(
group,
[spec.head * 0.98, 0.16, spec.head * 0.98],
[0, headTop + 0.035, -0.015],
spec.hair
);
box(
group,
[0.18, 0.26, spec.head * 0.7],
[-spec.head * 0.39, headTop - 0.02, -0.01],
spec.hair
);
box(
group,
[0.18, 0.26, spec.head * 0.7],
[spec.head * 0.39, headTop - 0.02, -0.01],
spec.hair
);
}
// -------------------------------------------------------------------------
// Role-specific silhouettes
// -------------------------------------------------------------------------
if (spec.id === "surveyor") {
// Long coat panels.
box(
group,
[spec.shoulder * 0.92, 0.74, 0.64],
[0, waistY - 0.38, 0],
spec.cloth
);
box(
group,
[0.12, 0.8, 0.07],
[-0.24, waistY - 0.28, 0.355],
spec.accent
);
box(
group,
[0.12, 0.8, 0.07],
[0.24, waistY - 0.28, 0.355],
spec.accent
);
// Flat-brimmed hat.
box(
group,
[spec.head * 2.1, 0.12, spec.head * 1.75],
[0, headTop + 0.11, 0],
spec.cloth
);
box(
group,
[spec.head * 0.88, 0.32, spec.head * 0.82],
[0, headTop + 0.29, 0],
spec.cloth
);
box(
group,
[spec.head * 0.9, 0.08, spec.head * 0.84],
[0, headTop + 0.2, 0],
spec.accent
);
// Staff and rolled plan.
box(
group,
[0.1, spec.legs + spec.torso + 0.95, 0.1],
[-0.86, (spec.legs + spec.torso + 0.95) / 2, 0.04],
0x73523d
);
box(
group,
[0.2, 0.2, 0.2],
[-0.86, spec.legs + spec.torso + 0.9, 0.04],
spec.accent
);
box(
group,
[0.72, 0.16, 0.18],
[0.68, waistY - 0.02, 0.34],
0xe5d9b7,
[0, 0, -0.12]
);
}
if (spec.id === "mason") {
// Apron and tool pouches.
box(
group,
[1.08, spec.torso * 0.88, 0.075],
[0, torsoCenter - 0.08, 0.325],
spec.accent
);
box(
group,
[0.32, 0.35, 0.2],
[-0.52, waistY - 0.12, 0.35],
0x6f4b38
);
box(
group,
[0.32, 0.35, 0.2],
[0.52, waistY - 0.12, 0.35],
0x6f4b38
);
// Forearms rotate forward and hold two stone blocks.
armL.rotation.x = -1.12;
armR.rotation.x = -1.12;
box(group, [0.54, 0.54, 0.54], [-0.43, shoulderY - 0.58, 0.7], 0x9d9b90);
box(group, [0.54, 0.54, 0.54], [0.43, shoulderY - 0.58, 0.7], 0x8b8c84);
}
if (spec.id === "vendor") {
// Two stepped skirt layers create a tapered silhouette.
const skirtTop = torsoBottom + 0.02;
const skirtBottom = 0.42;
const skirtHeight = skirtTop - skirtBottom;
box(
group,
[0.96, skirtHeight * 0.53, 0.62],
[0, skirtTop - skirtHeight * 0.265, 0],
spec.cloth
);
box(
group,
[1.17, skirtHeight * 0.5, 0.75],
[0, skirtBottom + skirtHeight * 0.24, 0],
0x5b405f
);
box(
group,
[0.78, 0.68, 0.075],
[0, torsoCenter - 0.07, 0.34],
spec.accent
);
// Square basket with visible produce.
const basketX = 0.9;
const basketY = waistY - 0.42;
box(group, [0.72, 0.1, 0.56], [basketX, basketY - 0.22, 0.05], 0x815b3e);
box(group, [0.08, 0.43, 0.56], [basketX - 0.32, basketY, 0.05], 0x9a704b);
box(group, [0.08, 0.43, 0.56], [basketX + 0.32, basketY, 0.05], 0x9a704b);
box(group, [0.72, 0.43, 0.08], [basketX, basketY, -0.23], 0x9a704b);
box(group, [0.72, 0.43, 0.08], [basketX, basketY, 0.33], 0x9a704b);
box(group, [0.28, 0.25, 0.28], [basketX - 0.18, basketY + 0.25, 0.04], 0xd69a32);
box(group, [0.27, 0.25, 0.27], [basketX + 0.16, basketY + 0.25, 0.12], 0xb64e3b);
box(group, [0.25, 0.25, 0.25], [basketX + 0.03, basketY + 0.29, -0.12], 0x77934b);
}
if (spec.id === "courier") {
// Oversized square satchel.
box(
group,
[0.72, 0.72, 0.34],
[-0.66, waistY - 0.02, -0.14],
0x68473a
);
box(
group,
[0.75, 0.24, 0.38],
[-0.66, waistY + 0.2, -0.14],
0x8c5d42
);
box(
group,
[0.16, 0.18, 0.1],
[-0.66, waistY + 0.12, 0.09],
spec.accent
);
// Diagonal front strap.
box(
group,
[0.08, 1.25, 0.045],
[0.08, torsoCenter + 0.03, 0.32],
0xe1bd77,
[0, 0, -0.62]
);
// Cap.
box(
group,
[spec.head * 1.03, 0.28, spec.head * 0.96],
[0, headTop + 0.09, 0],
spec.cloth
);
box(
group,
[spec.head * 1.15, 0.08, 0.42],
[0, headTop - 0.02, 0.31],
spec.cloth
);
// Letter corners visible above the bag.
box(group, [0.28, 0.18, 0.06], [-0.8, waistY + 0.43, -0.09], 0xf0dfbb, [0, 0, 0.12]);
box(group, [0.25, 0.18, 0.06], [-0.53, waistY + 0.4, -0.1], 0xe4cfaa, [0, 0, -0.1]);
}
if (spec.id === "fiddler") {
// Geometric box-frame string instrument.
const instrument = new THREE.Group();
instrument.position.set(0.22, torsoCenter - 0.02, 0.57);
group.add(instrument);
box(instrument, [0.1, 1.18, 0.12], [-0.28, 0.28, 0], 0x8c5c35);
box(instrument, [0.1, 1.18, 0.12], [0.28, 0.28, 0], 0x8c5c35);
box(instrument, [0.66, 0.1, 0.12], [0, 0.84, 0], 0x8c5c35);
box(instrument, [0.66, 0.1, 0.12], [0, -0.28, 0], 0x8c5c35);
box(instrument, [0.6, 0.5, 0.22], [0, -0.52, 0], 0xb77b42);
for (let i = 0; i < 3; i++) {
box(instrument, [0.018, 1.05, 0.025], [-0.13 + i * 0.13, 0.28, 0.08], 0xe6d5a8);
}
// Bow.
box(
group,
[0.045, 1.22, 0.045],
[0.7, torsoCenter, 0.62],
0xd5b36c,
[0, 0, -0.42]
);
armL.rotation.x = -1.05;
armR.rotation.x = -0.88;
}
if (spec.id === "planter") {
// Apron.
box(
group,
[0.92, 0.77, 0.075],
[0, torsoCenter - 0.1, 0.335],
spec.accent
);
// Wide square-brimmed hat.
box(
group,
[spec.head * 2.25, 0.11, spec.head * 1.95],
[0, headTop + 0.1, 0],
0xb59857
);
box(
group,
[spec.head * 0.95, 0.34, spec.head * 0.9],
[0, headTop + 0.27, 0],
0xb59857
);
box(
group,
[spec.head * 0.98, 0.09, spec.head * 0.93],
[0, headTop + 0.16, 0],
0x6b6d45
);
// Seedling crate.
const crateX = 0.72;
const crateY = waistY - 0.18;
box(group, [0.72, 0.1, 0.55], [crateX, crateY - 0.22, 0.43], 0x8b6547);
box(group, [0.08, 0.45, 0.55], [crateX - 0.32, crateY, 0.43], 0xa07951);
box(group, [0.08, 0.45, 0.55], [crateX + 0.32, crateY, 0.43], 0xa07951);
box(group, [0.72, 0.45, 0.08], [crateX, crateY, 0.14], 0xa07951);
box(group, [0.72, 0.45, 0.08], [crateX, crateY, 0.72], 0xa07951);
for (let i = 0; i < 3; i++) {
const px = crateX - 0.22 + i * 0.22;
box(group, [0.12, 0.25, 0.12], [px, crateY + 0.14, 0.4], 0x668a45);
box(group, [0.28, 0.09, 0.22], [px, crateY + 0.27, 0.4], 0x799d50);
}
// Trowel.
box(
group,
[0.08, 0.48, 0.08],
[-0.72, waistY - 0.15, 0.35],
0x75513b,
[0, 0, -0.25]
);
box(
group,
[0.27, 0.12, 0.08],
[-0.59, waistY - 0.38, 0.39],
0x8d9896,
[0, 0, -0.25]
);
}
if (spec.id === "lampkeeper") {
// Narrow long coat.
box(
group,
[spec.shoulder * 0.95, 0.72, 0.61],
[0, waistY - 0.36, 0],
spec.cloth
);
// Long pole.
const poleHeight = spec.legs + spec.torso + 0.8;
box(
group,
[0.11, poleHeight, 0.11],
[0.84, poleHeight / 2, 0.02],
0x4d5050
);
box(
group,
[0.78, 0.1, 0.1],
[1.08, poleHeight - 0.03, 0.02],
0x4d5050
);
// Square hanging lantern.
box(
group,
[0.58, 0.66, 0.58],
[1.36, poleHeight - 0.48, 0.02],
0x394347
);
box(
group,
[0.36, 0.42, 0.36],
[1.36, poleHeight - 0.48, 0.31],
windowMaterial
);
box(
group,
[0.72, 0.1, 0.72],
[1.36, poleHeight - 0.13, 0.02],
0x303a3e
);
armR.rotation.z = -0.12;
}
if (spec.id === "scribe") {
// Tall square collar.
box(
group,
[0.78, 0.34, 0.66],
[0, torsoTop + 0.13, 0],
spec.accent
);
// Stack of books carried at the side.
const bookColors = [0x8b4f42, 0x3f6972, 0xb9974d];
for (let i = 0; i < 3; i++) {
box(
group,
[0.68 - i * 0.03, 0.18, 0.48],
[-0.76, waistY + 0.25 + i * 0.2, -0.16],
bookColors[i],
[0, 0, i % 2 ? 0.035 : -0.025]
);
}
// Large folio under the opposite arm.
box(
group,
[0.18, 0.75, 0.58],
[0.7, waistY + 0.06, 0.4],
0x4d3948
);
box(
group,
[0.2, 0.62, 0.48],
[0.72, waistY + 0.07, 0.42],
spec.accent
);
armR.rotation.x = -0.72;
}
const totalHeight = headTop + 0.45;
group.traverse((object) => {
if (object.isMesh) {
object.userData.figureId = spec.id;
pickables.push(object);
}
});
world.add(group);
const figure = {
spec,
group,
armL,
armR,
phase: random() * Math.PI * 2,
baseY: group.position.y,
totalHeight
};
figures.push(figure);
return figure;
}
specs.forEach(makeCharacter);
// -------------------------------------------------------------------------
// Roster and projected labels
// -------------------------------------------------------------------------
const rosterList = document.querySelector("#roster-list");
const cards = new Map();
const callouts = new Map();
for (const spec of specs) {
const card = document.createElement("div");
card.className = "character-card";
card.tabIndex = 0;
const total = spec.legs + spec.torso + spec.head;
const legHeight = Math.round((spec.legs / total) * 32);
const torsoHeight = Math.round((spec.torso / total) * 32);
const headHeight = Math.max(5, Math.round((spec.head / total) * 32));
const torsoWidth = Math.max(8, Math.min(23, Math.round((spec.shoulder / 1.75) * 23)));
card.innerHTML = `
<span class="mini" style="--leg:${legHeight}px;--torso:${torsoHeight}px;--head:${headHeight}px;--wide:${torsoWidth}px">
<i></i><b></b><em></em>
</span>
<span>
<span class="card-name">
<strong>${spec.name}</strong>
<span>${spec.role}</span>
</span>
<span class="card-cue">${spec.proportion} · ${spec.cue}</span>
</span>
`;
card.addEventListener("click", () => selectCharacter(spec.id));
card.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
selectCharacter(spec.id);
}
});
rosterList.appendChild(card);
cards.set(spec.id, card);
const callout = document.createElement("div");
callout.className = "callout";
callout.innerHTML = `<span>${spec.name}</span><b>${spec.role}</b>`;
document.body.appendChild(callout);
callouts.set(spec.id, callout);
}
let selectedId = null;
function selectCharacter(id) {
selectedId = selectedId === id ? null : id;
for (const [figureId, card] of cards) {
card.classList.toggle("selected", figureId === selectedId);
}
for (const [figureId, callout] of callouts) {
callout.classList.toggle("selected", figureId === selectedId);
}
}
let labelsVisible = true;
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, pan, keyboard, and touch pinch
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.48,
phi: 1.02,
radius: 24,
target: new THREE.Vector3(0, 1.65, 0.55)
};
const initialCamera = {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
};
function updateCamera() {
cameraState.phi = THREE.MathUtils.clamp(cameraState.phi, 0.38, 1.38);
cameraState.radius = THREE.MathUtils.clamp(cameraState.radius, 11, 38);
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.theta = initialCamera.theta;
cameraState.phi = initialCamera.phi;
cameraState.radius = initialCamera.radius;
cameraState.target.copy(initialCamera.target);
updateCamera();
}
updateCamera();
const pointers = new Map();
let lastPinch = null;
let pointerStart = null;
let pointerMoved = false;
const canvas = renderer.domElement;
function pinchState() {
const values = [...pointers.values()];
if (values.length < 2) return null;
const a = values[0];
const b = values[1];
return {
distance: Math.hypot(a.x - b.x, a.y - b.y),
x: (a.x + b.x) / 2,
y: (a.y + b.y) / 2
};
}
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
pointerStart = { x: event.clientX, y: event.clientY };
pointerMoved = false;
} else {
lastPinch = pinchState();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
if (Math.abs(event.clientX - pointerStart.x) + Math.abs(event.clientY - pointerStart.y) > 4) {
pointerMoved = true;
}
if (event.buttons === 2 || event.shiftKey) {
const panScale = cameraState.radius * 0.0014;
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.z += dy * panScale;
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi -= dy * 0.006;
}
} else {
const nextPinch = pinchState();
if (lastPinch && nextPinch) {
cameraState.radius *=
lastPinch.distance / Math.max(1, nextPinch.distance);
const panScale = cameraState.radius * 0.0014;
const right = new THREE.Vector3(
Math.cos(cameraState.theta),
0,
-Math.sin(cameraState.theta)
);
cameraState.target.addScaledVector(
right,
(nextPinch.x - lastPinch.x) * panScale
);
cameraState.target.z +=
(nextPinch.y - lastPinch.y) * panScale;
}
lastPinch = nextPinch;
pointerMoved = true;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinch = pointers.size >= 2 ? pinchState() : null;
}
canvas.addEventListener("pointerup", (event) => {
releasePointer(event);
if (
!pointerMoved &&
pointerStart &&
Math.hypot(
event.clientX - pointerStart.x,
event.clientY - pointerStart.y
) < 5 &&
event.button === 0
) {
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2(
(event.clientX / window.innerWidth) * 2 - 1,
-(event.clientY / window.innerHeight) * 2 + 1
);
raycaster.setFromCamera(mouse, camera);
const hits = raycaster.intersectObjects(pickables, false);
if (hits.length) {
const id = hits[0].object.userData.figureId;
if (id) selectCharacter(id);
}
}
});
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetCamera();
} else if (key === "arrowleft") {
cameraState.theta -= 0.08;
} else if (key === "arrowright") {
cameraState.theta += 0.08;
} else if (key === "arrowup") {
cameraState.phi -= 0.06;
} else if (key === "arrowdown") {
cameraState.phi += 0.06;
} else if (key === "+" || key === "=") {
cameraState.radius *= 0.92;
} else if (key === "-") {
cameraState.radius *= 1.08;
} else {
return;
}
event.preventDefault();
updateCamera();
});
// -------------------------------------------------------------------------
// Interface controls
// -------------------------------------------------------------------------
document.querySelector("#reset-view").addEventListener("click", resetCamera);
const labelButton = document.querySelector("#toggle-labels");
labelButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelButton.classList.toggle("active", labelsVisible);
for (const callout of callouts.values()) {
callout.style.display = labelsVisible ? "block" : "none";
}
});
const duskButton = document.querySelector("#toggle-dusk");
let dusk = false;
duskButton.addEventListener("click", () => {
dusk = !dusk;
duskButton.classList.toggle("active", dusk);
duskButton.textContent = dusk ? "Daylight" : "Dusk";
scene.background.copy(dusk ? duskColor : dayColor);
scene.fog.color.copy(dusk ? duskColor : dayColor);
hemisphere.intensity = dusk ? 0.85 : 2.15;
sun.intensity = dusk ? 0.62 : 3.1;
fillLight.intensity = dusk ? 0.35 : 0.65;
windowMaterial.emissiveIntensity = dusk ? 1.8 : 0.25;
renderer.toneMappingExposure = dusk ? 1.22 : 1.08;
for (const light of lampLights) {
light.intensity = dusk ? 5.2 : 0;
}
});
// -------------------------------------------------------------------------
// Animation and projected DOM labels
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
function animate() {
const elapsed = clock.getElapsedTime();
// Subtle idle motion preserves the deliberately block-like construction.
for (const figure of figures) {
const { spec, group, armL, armR, phase, baseY } = figure;
const bob = Math.sin(elapsed * 1.25 + phase) * 0.012;
group.position.y = baseY + bob;
const armSwing = Math.sin(elapsed * 0.9 + phase) * 0.025;
if (spec.id !== "mason" && spec.id !== "fiddler") {
armL.rotation.x = armSwing;
armR.rotation.x = -armSwing;
}
}
for (const jet of waterJets) {
jet.scale.y = 0.88 + Math.sin(elapsed * 4.2 + jet.position.x * 3) * 0.12;
}
water.material.opacity = 0.8 + Math.sin(elapsed * 1.6) * 0.035;
for (const cloud of clouds) {
cloud.group.position.x += cloud.speed * 0.008;
if (cloud.group.position.x > 16) cloud.group.position.x = -16;
}
if (labelsVisible) {
for (const figure of figures) {
const callout = callouts.get(figure.spec.id);
projected.set(0, figure.totalHeight + 0.12, 0);
figure.group.localToWorld(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
callout.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
callout.style.left = `${x}px`;
callout.style.top = `${y}px`;
}
}
}
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.render(scene, camera);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 400);
animate();
</script>
</body>
</html>
```