Prompt specification
Build or customize the Three.js 3D scene "Galaxy Morphology Museum Hall" 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: Galaxy Morphology Museum Hall
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/galaxy-morphology-museum-hall-x3783
Scene Description Prompt:
Build a voxel museum of schematic galaxy shapes with matching viewing controls; present descriptive categories without a single evolutionary sequence. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (galaxy-morphology-museum-hall-x3783):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Galaxy Museum — Form Atlas</title>
<style>
:root {
--bg: #070910;
--panel: rgba(11, 15, 24, 0.82);
--panel-strong: rgba(9, 13, 21, 0.94);
--line: rgba(172, 199, 220, 0.17);
--line-bright: rgba(172, 220, 244, 0.38);
--text: #edf3f7;
--muted: #8e9ba9;
--cyan: #74e5ee;
--gold: #ffd28b;
--violet: #b99cff;
}
* {
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;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#stage,
#labels {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.exhibit-label {
position: absolute;
min-width: 140px;
padding: 8px 11px;
transform: translate(-50%, -100%);
border: 1px solid var(--line);
border-top-color: rgba(255, 255, 255, 0.25);
background: rgba(5, 8, 13, 0.78);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(10px);
opacity: 0.62;
transition: opacity 180ms ease, border-color 180ms ease;
}
.exhibit-label.active {
opacity: 1;
border-color: rgba(116, 229, 238, 0.65);
}
.exhibit-label strong {
display: block;
font-size: 11px;
line-height: 1.1;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.exhibit-label span {
display: block;
margin-top: 4px;
color: var(--muted);
font: 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}
header {
position: fixed;
z-index: 10;
top: 0;
left: 0;
right: 0;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
padding: 24px 28px;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
}
.brand-mark {
width: 35px;
height: 35px;
border: 1px solid rgba(116, 229, 238, 0.52);
background:
linear-gradient(90deg, transparent 46%, rgba(116, 229, 238, 0.35) 47% 53%, transparent 54%),
linear-gradient(transparent 46%, rgba(116, 229, 238, 0.35) 47% 53%, transparent 54%);
box-shadow: inset 0 0 20px rgba(116, 229, 238, 0.07);
}
.brand h1 {
margin: 0;
font-size: 15px;
font-weight: 650;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.header-actions {
display: flex;
gap: 8px;
pointer-events: auto;
}
.ui-button {
min-height: 36px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 2px;
background: rgba(8, 12, 19, 0.74);
color: #c7d1da;
font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}
.ui-button:hover,
.ui-button:focus-visible {
border-color: var(--line-bright);
color: #fff;
background: rgba(22, 31, 44, 0.88);
outline: none;
}
.ui-button[aria-pressed="true"] {
border-color: rgba(116, 229, 238, 0.65);
color: var(--cyan);
}
.catalog {
position: fixed;
z-index: 8;
top: 102px;
left: 28px;
bottom: 126px;
width: 305px;
overflow: auto;
padding: 18px;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: #344152 transparent;
}
.catalog-kicker,
.panel-kicker {
color: var(--cyan);
font: 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.catalog h2 {
margin: 8px 0 7px;
font-size: 21px;
font-weight: 550;
letter-spacing: -0.025em;
}
.catalog-intro {
margin: 0 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.classification-note {
margin: 0 0 16px;
padding: 10px 11px;
border-left: 2px solid var(--gold);
background: rgba(255, 210, 139, 0.055);
color: #b9b5aa;
font: 9px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.category-list {
display: grid;
gap: 8px;
}
.category-card {
display: grid;
grid-template-columns: 45px 1fr;
gap: 12px;
width: 100%;
padding: 12px;
border: 1px solid transparent;
background: rgba(255, 255, 255, 0.025);
text-align: left;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
.category-card:hover,
.category-card:focus-visible {
border-color: var(--line);
background: rgba(255, 255, 255, 0.045);
outline: none;
}
.category-card.active {
border-color: rgba(116, 229, 238, 0.48);
background: rgba(116, 229, 238, 0.075);
}
.category-card strong {
display: block;
margin-top: 1px;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.025em;
}
.category-card p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.glyph {
position: relative;
display: block;
width: 42px;
height: 42px;
border: 1px solid rgba(255, 255, 255, 0.08);
background: rgba(0, 0, 0, 0.2);
overflow: hidden;
}
.glyph i {
position: absolute;
width: 5px;
height: 5px;
background: var(--cyan);
box-shadow: 0 0 8px rgba(116, 229, 238, 0.45);
}
.glyph.spiral i:nth-child(1) { left: 18px; top: 18px; }
.glyph.spiral i:nth-child(2) { left: 13px; top: 13px; }
.glyph.spiral i:nth-child(3) { left: 10px; top: 9px; }
.glyph.spiral i:nth-child(4) { left: 25px; top: 23px; }
.glyph.spiral i:nth-child(5) { left: 29px; top: 29px; }
.glyph.spiral i:nth-child(6) { left: 31px; top: 8px; }
.glyph.irregular i:nth-child(1) { left: 8px; top: 12px; }
.glyph.irregular i:nth-child(2) { left: 12px; top: 9px; }
.glyph.irregular i:nth-child(3) { left: 16px; top: 13px; }
.glyph.irregular i:nth-child(4) { left: 26px; top: 25px; }
.glyph.irregular i:nth-child(5) { left: 30px; top: 29px; }
.glyph.irregular i:nth-child(6) { left: 23px; top: 7px; }
.glyph.elliptical i:nth-child(1) { left: 15px; top: 12px; }
.glyph.elliptical i:nth-child(2) { left: 18px; top: 14px; }
.glyph.elliptical i:nth-child(3) { left: 22px; top: 16px; }
.glyph.elliptical i:nth-child(4) { left: 26px; top: 19px; }
.glyph.elliptical i:nth-child(5) { left: 11px; top: 21px; }
.glyph.elliptical i:nth-child(6) { left: 24px; top: 23px; }
.glyph.barred i:nth-child(1) { left: 9px; top: 20px; width: 25px; height: 3px; }
.glyph.barred i:nth-child(2) { left: 19px; top: 17px; }
.glyph.barred i:nth-child(3) { left: 22px; top: 20px; }
.glyph.barred i:nth-child(4) { left: 26px; top: 24px; }
.glyph.barred i:nth-child(5) { left: 29px; top: 28px; }
.glyph.barred i:nth-child(6) { left: 10px; top: 11px; }
.glyph.lenticular i:nth-child(1) { left: 8px; top: 17px; }
.glyph.lenticular i:nth-child(2) { left: 12px; top: 16px; }
.glyph.lenticular i:nth-child(3) { left: 16px; top: 15px; }
.glyph.lenticular i:nth-child(4) { left: 20px; top: 15px; }
.glyph.lenticular i:nth-child(5) { left: 24px; top: 16px; }
.glyph.lenticular i:nth-child(6) { left: 28px; top: 17px; }
.inspection {
position: fixed;
z-index: 7;
top: 102px;
right: 28px;
width: 288px;
padding: 17px 18px;
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(18px);
box-shadow: 0 20px 55px rgba(0, 0, 0, 0.22);
}
.inspection h2 {
margin: 8px 0 7px;
font-size: 18px;
font-weight: 550;
}
.inspection p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.inspection-meta {
margin-top: 12px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #b8c3cc;
font: 9px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.controls {
position: fixed;
z-index: 9;
left: 50%;
bottom: 22px;
width: min(840px, calc(100vw - 56px));
transform: translateX(-50%);
border: 1px solid var(--line);
background: var(--panel-strong);
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(20px);
}
.controls-top {
display: grid;
grid-template-columns: minmax(150px, 0.8fr) minmax(250px, 1.4fr) auto;
align-items: center;
gap: 18px;
min-height: 66px;
padding: 12px 15px;
}
.controls-title strong {
display: block;
margin-top: 4px;
font-size: 11px;
font-weight: 600;
letter-spacing: 0.04em;
}
.layer-controls {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.layer-chip {
min-height: 29px;
padding: 0 10px;
border: 1px solid var(--line);
background: transparent;
color: var(--muted);
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
}
.layer-chip[aria-pressed="true"] {
border-color: rgba(116, 229, 238, 0.45);
background: rgba(116, 229, 238, 0.075);
color: var(--cyan);
}
.layer-chip:hover,
.layer-chip:focus-visible {
color: white;
outline: none;
}
.control-buttons {
display: flex;
gap: 6px;
}
.control-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
border-top: 1px solid var(--line);
}
.slider-control {
padding: 10px 15px 12px;
border-right: 1px solid var(--line);
}
.slider-control:last-child {
border-right: 0;
}
.slider-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
color: var(--muted);
font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.slider-value {
color: #d7e0e7;
letter-spacing: 0;
}
input[type="range"] {
width: 100%;
height: 15px;
margin: 7px 0 0;
appearance: none;
background: transparent;
cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
height: 2px;
background: #34404e;
}
input[type="range"]::-webkit-slider-thumb {
width: 11px;
height: 11px;
margin-top: -4.5px;
appearance: none;
border: 1px solid #a7e9ed;
border-radius: 0;
background: #16232c;
box-shadow: 0 0 8px rgba(116, 229, 238, 0.25);
}
input[type="range"]::-moz-range-track {
height: 2px;
background: #34404e;
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 1px solid #a7e9ed;
border-radius: 0;
background: #16232c;
}
.hint {
position: fixed;
z-index: 6;
right: 29px;
bottom: 112px;
color: rgba(182, 196, 207, 0.55);
font: 8px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.06em;
text-align: right;
text-transform: uppercase;
pointer-events: none;
}
.modal {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(2, 4, 8, 0.78);
backdrop-filter: blur(10px);
}
.modal[hidden] {
display: none;
}
.modal-card {
width: min(520px, 100%);
padding: 25px;
border: 1px solid var(--line-bright);
background: #0b1019;
box-shadow: 0 30px 100px rgba(0, 0, 0, 0.55);
}
.modal-card h2 {
margin: 8px 0 16px;
font-size: 22px;
font-weight: 550;
}
.modal-card p,
.modal-card li {
color: #aab6c1;
font-size: 12px;
line-height: 1.65;
}
.modal-card ul {
padding-left: 18px;
}
.modal-card .ui-button {
margin-top: 10px;
}
@media (max-width: 1050px) {
.catalog {
width: 270px;
}
.inspection {
width: 250px;
}
.controls-top {
grid-template-columns: 150px 1fr;
}
.control-buttons {
grid-column: 1 / -1;
}
}
@media (max-width: 760px) {
header {
padding: 15px;
}
.brand p,
#labelsButton {
display: none;
}
.brand-mark {
width: 30px;
height: 30px;
}
.brand h1 {
font-size: 12px;
}
.catalog {
top: 72px;
left: 14px;
right: 14px;
bottom: auto;
width: auto;
max-height: 155px;
padding: 12px;
}
.catalog-copy,
.classification-note,
.inspection {
display: none;
}
.category-list {
display: flex;
overflow-x: auto;
padding-bottom: 2px;
}
.category-card {
flex: 0 0 210px;
}
.controls {
left: 14px;
right: 14px;
bottom: 14px;
width: auto;
transform: none;
}
.controls-top {
grid-template-columns: 1fr;
gap: 9px;
}
.layer-controls {
max-height: 58px;
overflow-y: auto;
}
.control-buttons {
grid-column: auto;
}
.control-grid {
grid-template-columns: 1fr 1fr;
}
.slider-control:last-child {
grid-column: 1 / -1;
border-top: 1px solid var(--line);
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Interactive 3D voxel galaxy museum"></div>
<div id="labels" aria-hidden="true"></div>
<header>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Voxel Galaxy Museum</h1>
<p>Schematic form atlas · descriptive collection</p>
</div>
</div>
<div class="header-actions">
<button class="ui-button" id="overviewButton" type="button">All forms</button>
<button class="ui-button" id="labelsButton" type="button" aria-pressed="true">Labels</button>
<button class="ui-button" id="helpButton" type="button">Controls</button>
</div>
</header>
<aside class="catalog" aria-label="Galaxy categories">
<div class="catalog-copy">
<div class="catalog-kicker">Descriptive index</div>
<h2>Forms without chronology</h2>
<p class="catalog-intro">
Five schematic structures occupy the same museum. Choose any category
to inspect the components that define it.
</p>
<div class="classification-note">
Classification, not chronology.<br>
No route, lineage, or transition is implied.
</div>
</div>
<div class="category-list" id="categoryList"></div>
</aside>
<section class="inspection" aria-live="polite">
<div class="panel-kicker" id="inspectionKicker">Gallery overview</div>
<h2 id="inspectionTitle">The form atlas</h2>
<p id="inspectionText">
A side-by-side collection of schematic galactic arrangements.
The categories describe visible structure rather than stages in a sequence.
</p>
<div class="inspection-meta" id="inspectionMeta">
Drag to orbit · wheel or pinch to zoom · select any exhibit
</div>
</section>
<section class="controls" aria-label="Viewing controls">
<div class="controls-top">
<div class="controls-title">
<div class="panel-kicker">Viewing controls</div>
<strong id="controlsTitle">Gallery / Orbit</strong>
</div>
<div class="layer-controls" id="layerControls">
<button class="layer-chip" type="button" disabled>
Select an exhibit to toggle components
</button>
</div>
<div class="control-buttons">
<button class="ui-button" id="spinButton" type="button" aria-pressed="false">
Auto-turn
</button>
<button class="ui-button" id="resetButton" type="button">Reset</button>
</div>
</div>
<div class="control-grid">
<label class="slider-control">
<span class="slider-label">
Azimuth <span class="slider-value" id="azimuthValue">0°</span>
</span>
<input id="azimuthSlider" type="range" min="-180" max="180" value="0">
</label>
<label class="slider-control">
<span class="slider-label">
Elevation <span class="slider-value" id="elevationValue">25°</span>
</span>
<input id="elevationSlider" type="range" min="-70" max="78" value="25">
</label>
<label class="slider-control">
<span class="slider-label">
Magnification <span class="slider-value" id="distanceValue">16.5</span>
</span>
<input id="distanceSlider" type="range" min="4.5" max="24" step="0.1" value="16.5">
</label>
</div>
</section>
<div class="hint">
Left drag — orbit<br>
Right / shift drag — pan<br>
Wheel / pinch — zoom
</div>
<div class="modal" id="helpModal" hidden>
<div class="modal-card" role="dialog" aria-modal="true" aria-labelledby="helpTitle">
<div class="catalog-kicker">Museum controls</div>
<h2 id="helpTitle">Inspect without a prescribed route</h2>
<p>
Each exhibit is an independently selectable schematic form. Its component
buttons correspond to the structural layers used to build that category.
</p>
<ul>
<li>Drag with the left mouse button to orbit.</li>
<li>Right-drag or shift-drag to pan the viewing target.</li>
<li>Use the mouse wheel or a two-finger pinch to zoom.</li>
<li>Click a voxel exhibit or an index card to focus it.</li>
<li>Toggle component chips to isolate structural layers.</li>
<li>Use the sliders for exact azimuth, elevation, and magnification.</li>
</ul>
<button class="ui-button" id="closeHelpButton" type="button">Return to museum</button>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const labelsLayer = document.getElementById("labels");
const categoryList = document.getElementById("categoryList");
const layerControls = document.getElementById("layerControls");
const categories = [
{
id: "spiral",
name: "Spiral",
short: "Curved arms",
description: "A bright nucleus anchors curved, clotted arms.",
detail: "The schematic is organized around a luminous center and two broad spiral bands.",
position: new THREE.Vector3(-5.35, 4.15, -1.15),
rotation: new THREE.Euler(-0.12, 0.14, -0.12),
seed: 117,
parts: [
["core", "Nucleus"],
["arms", "Spiral arms"],
["halo", "Halo"]
]
},
{
id: "irregular",
name: "Irregular",
short: "Asymmetric structure",
description: "Knots and diffuse material form an asymmetric body.",
detail: "No single rotationally ordered disk or central bar organizes this schematic form.",
position: new THREE.Vector3(0, 4.15, -4.1),
rotation: new THREE.Euler(-0.08, -0.18, 0.2),
seed: 289,
parts: [
["knots", "Bright knots"],
["body", "Diffuse body"],
["dust", "Dust lanes"]
]
},
{
id: "elliptical",
name: "Elliptical",
short: "Continuous envelope",
description: "A rounded envelope becomes progressively less dense outward.",
detail: "The schematic emphasizes a smooth, continuous distribution without conspicuous arms.",
position: new THREE.Vector3(5.35, 4.15, -1.15),
rotation: new THREE.Euler(-0.08, 0.22, 0.08),
seed: 431,
parts: [
["core", "Dense core"],
["envelope", "Diffuse envelope"]
]
},
{
id: "barred",
name: "Barred spiral",
short: "Central bar",
description: "A stellar bar crosses the center and connects to curved arms.",
detail: "The bar interrupts the nucleus, while spiral bands appear to begin near its ends.",
position: new THREE.Vector3(-3.15, 4.15, 4.15),
rotation: new THREE.Euler(-0.1, -0.12, 0.1),
seed: 577,
parts: [
["core", "Nucleus"],
["bar", "Central bar"],
["arms", "Outer arms"]
]
},
{
id: "lenticular",
name: "Lenticular",
short: "Smooth disk",
description: "A flattened disk surrounds a compact central bulge.",
detail: "The disk is schematically smooth, with no strong spiral pattern in this example.",
position: new THREE.Vector3(3.15, 4.15, 4.15),
rotation: new THREE.Euler(-0.07, 0.1, -0.06),
seed: 733,
parts: [
["bulge", "Central bulge"],
["disk", "Disk"],
["halo", "Faint halo"]
]
}
];
const categoryById = new Map(categories.map(category => [category.id, category]));
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x070910);
scene.fog = new THREE.Fog(0x070910, 16, 37);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0x9bc8e8, 0x15101a, 1.4);
scene.add(hemisphere);
const ambient = new THREE.AmbientLight(0x64758a, 0.65);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xd9efff, 2.2);
keyLight.position.set(-5, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7a5eff, 1.1);
rimLight.position.set(9, 7, -9);
scene.add(rimLight);
const models = new Map();
const raycastMeshes = [];
const labelElements = new Map();
function randomGenerator(seed) {
let state = seed >>> 0;
return function random() {
state = (1664525 * state + 1013904223) >>> 0;
return state / 4294967296;
};
}
function gaussian(random) {
return (
Math.sqrt(-2 * Math.log(Math.max(random(), 0.00001))) *
Math.cos(2 * Math.PI * random())
);
}
function spherePositions(count, rx, ry, rz, random, shell = false) {
const points = [];
for (let i = 0; i < count; i++) {
const z = random() * 2 - 1;
const angle = random() * Math.PI * 2;
const planar = Math.sqrt(Math.max(0, 1 - z * z));
let radius = Math.cbrt(random());
if (shell) {
radius = 0.72 + random() * 0.28;
}
points.push([
Math.cos(angle) * planar * rx * radius,
Math.sin(angle) * planar * ry * radius,
z * rz * radius
]);
}
return points;
}
function addVoxelLayer(root, categoryId, key, positions, baseColor, options = {}) {
const group = new THREE.Group();
group.name = key;
const cell = options.cell ?? 0.135;
const geometry = new THREE.BoxGeometry(cell, cell, cell);
const color = new THREE.Color(baseColor);
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
emissive: color.clone().multiplyScalar(0.72),
emissiveIntensity: 0.13,
roughness: 0.66,
metalness: 0.08,
transparent: (options.opacity ?? 1) < 0.99,
opacity: options.opacity ?? 1,
depthWrite: (options.opacity ?? 1) > 0.6
});
const mesh = new THREE.InstancedMesh(geometry, material, positions.length);
const dummy = new THREE.Object3D();
const instanceColor = new THREE.Color();
const random = randomGenerator(9917 + positions.length * 17);
for (let i = 0; i < positions.length; i++) {
const point = positions[i];
dummy.position.set(point[0], point[1], point[2]);
dummy.scale.setScalar(0.82 + random() * 0.34);
dummy.rotation.set(
(random() - 0.5) * 0.08,
(random() - 0.5) * 0.08,
(random() - 0.5) * 0.08
);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
instanceColor.copy(color);
instanceColor.offsetHSL(
(random() - 0.5) * 0.035,
(random() - 0.5) * 0.09,
(random() - 0.5) * 0.13
);
mesh.setColorAt(i, instanceColor);
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
mesh.userData.categoryId = categoryId;
mesh.castShadow = (options.opacity ?? 1) > 0.75;
mesh.receiveShadow = true;
root.add(group);
group.add(mesh);
raycastMeshes.push(mesh);
return {
group,
mesh,
material,
baseOpacity: options.opacity ?? 1
};
}
function buildSpiral(root, category, random) {
const core = spherePositions(430, 0.58, 0.58, 0.46, random);
addVoxelLayer(root, category.id, "core", core, 0xffd48a, { cell: 0.14 });
const arms = [];
for (let arm = 0; arm < 2; arm++) {
for (let i = 0; i < 1450; i++) {
const t = Math.pow(random(), 0.78);
const angle = arm * Math.PI + t * Math.PI * 4.35;
const radius = 0.52 + t * 3.03;
const width = 0.045 + (1 - t) * 0.22;
arms.push([
Math.cos(angle) * radius + gaussian(random) * width,
Math.sin(angle) * radius * 0.88 + gaussian(random) * width,
gaussian(random) * 0.16 * (1 - t * 0.35)
]);
}
}
addVoxelLayer(root, category.id, "arms", arms, 0x66d9e7, { cell: 0.115 });
const halo = spherePositions(430, 3.55, 3.1, 1.1, random, true);
addVoxelLayer(root, category.id, "halo", halo, 0x7e77c8, {
cell: 0.105,
opacity: 0.2
});
}
function buildIrregular(root, category, random) {
const centers = [
[-1.55, 0.65, 0.05],
[-0.45, -0.82, -0.08],
[1.25, 0.58, 0.12],
[0.52, 1.36, -0.12],
[1.78, -0.92, 0.16]
];
const knots = [];
for (const center of centers) {
for (let i = 0; i < 330; i++) {
knots.push([
center[0] + gaussian(random) * 0.42,
center[1] + gaussian(random) * 0.38,
center[2] + gaussian(random) * 0.24
]);
}
}
addVoxelLayer(root, category.id, "knots", knots, 0x7de4eb, { cell: 0.125 });
const body = [];
for (let i = 0; i < 900; i++) {
body.push([
gaussian(random) * 1.72,
gaussian(random) * 1.12,
gaussian(random) * 0.48
]);
}
addVoxelLayer(root, category.id, "body", body, 0x9a83c9, {
cell: 0.12,
opacity: 0.64
});
const dust = [];
for (let i = 0; i < 380; i++) {
const t = random() * Math.PI * 1.4 - 0.4;
const radius = 1.2 + random() * 0.7;
dust.push([
Math.cos(t) * radius + gaussian(random) * 0.11,
Math.sin(t) * radius * 0.6 + gaussian(random) * 0.1,
0.28 + gaussian(random) * 0.06
]);
}
addVoxelLayer(root, category.id, "dust", dust, 0x35445d, {
cell: 0.13,
opacity: 0.82
});
}
function buildElliptical(root, category, random) {
const core = spherePositions(780, 0.9, 1.02, 0.7, random);
addVoxelLayer(root, category.id, "core", core, 0xffd096, { cell: 0.135 });
const envelope = [];
for (let i = 0; i < 1550; i++) {
const radius = 0.52 + Math.pow(random(), 0.58) * 0.48;
const z = random() * 2 - 1;
const angle = random() * Math.PI * 2;
const planar = Math.sqrt(Math.max(0, 1 - z * z));
envelope.push([
Math.cos(angle) * planar * 2.45 * radius,
Math.sin(angle) * planar * 2.1 * radius,
z * 1.35 * radius
]);
}
addVoxelLayer(root, category.id, "envelope", envelope, 0xe2a98e, {
cell: 0.13,
opacity: 0.72
});
}
function buildBarred(root, category, random) {
const core = spherePositions(360, 0.56, 0.56, 0.45, random);
addVoxelLayer(root, category.id, "core", core, 0xffd08a, { cell: 0.14 });
const bar = [];
for (let i = 0; i < 430; i++) {
const x = (random() - 0.5) * 3.05;
bar.push([
x,
gaussian(random) * (0.1 + (1 - Math.abs(x) / 1.7) * 0.08),
gaussian(random) * 0.13
]);
}
addVoxelLayer(root, category.id, "bar", bar, 0xf3a477, { cell: 0.14 });
const arms = [];
for (let arm = 0; arm < 2; arm++) {
for (let i = 0; i < 1150; i++) {
const t = Math.pow(random(), 0.8);
const angle = arm * Math.PI + t * Math.PI * 4.05;
const radius = 1.05 + t * 2.65;
const width = 0.04 + (1 - t) * 0.2;
arms.push([
Math.cos(angle) * radius + gaussian(random) * width,
Math.sin(angle) * radius * 0.87 + gaussian(random) * width,
gaussian(random) * 0.14
]);
}
}
addVoxelLayer(root, category.id, "arms", arms, 0x62dbe6, { cell: 0.115 });
}
function buildLenticular(root, category, random) {
const bulge = spherePositions(420, 0.72, 0.54, 0.48, random);
addVoxelLayer(root, category.id, "bulge", bulge, 0xffd18d, { cell: 0.14 });
const disk = [];
for (let i = 0; i < 2250; i++) {
const radius = Math.sqrt(random()) * 2.75;
const angle = random() * Math.PI * 2;
disk.push([
Math.cos(angle) * radius,
Math.sin(angle) * radius * 0.48,
gaussian(random) * (0.08 + (1 - radius / 2.75) * 0.035)
]);
}
addVoxelLayer(root, category.id, "disk", disk, 0xaab7ec, {
cell: 0.125,
opacity: 0.92
});
const halo = [];
for (let i = 0; i < 420; i++) {
const radius = 2.3 + random() * 0.8;
const angle = random() * Math.PI * 2;
halo.push([
Math.cos(angle) * radius,
Math.sin(angle) * radius * 0.55,
gaussian(random) * 0.24
]);
}
addVoxelLayer(root, category.id, "halo", halo, 0x6679a6, {
cell: 0.105,
opacity: 0.19
});
}
function makePlaqueTexture(name, accent) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 180;
const context = canvas.getContext("2d");
context.fillStyle = "rgba(5, 8, 13, 0.94)";
context.fillRect(0, 0, canvas.width, canvas.height);
context.strokeStyle = accent;
context.lineWidth = 5;
context.strokeRect(3, 3, canvas.width - 6, canvas.height - 6);
context.fillStyle = accent;
context.font = "600 42px ui-monospace, monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(name.toUpperCase(), canvas.width / 2, canvas.height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(4, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0d121b,
roughness: 0.87,
metalness: 0.18
});
const floor = new THREE.Mesh(new THREE.PlaneGeometry(28, 24), floorMaterial);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(28, 28, 0x263747, 0x18232e);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.5;
scene.add(grid);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x0b1018,
roughness: 0.9,
metalness: 0.08
});
const backWall = new THREE.Mesh(new THREE.BoxGeometry(24, 9, 0.3), wallMaterial);
backWall.position.set(0, 4.5, -10);
backWall.receiveShadow = true;
scene.add(backWall);
const leftWall = new THREE.Mesh(new THREE.BoxGeometry(0.3, 9, 20), wallMaterial);
leftWall.position.set(-12, 4.5, 0);
scene.add(leftWall);
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0x111925,
emissive: 0x10202b,
emissiveIntensity: 0.25,
roughness: 0.75,
metalness: 0.2
});
for (let i = -2; i <= 2; i++) {
const panel = new THREE.Mesh(new THREE.BoxGeometry(3.8, 6.2, 0.08), panelMaterial);
panel.position.set(i * 4.35, 4.3, -9.8);
scene.add(panel);
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 6.3, 0.025),
new THREE.MeshBasicMaterial({ color: 0x4d6c79 })
);
seam.position.set(i * 4.35 + 2.08, 4.3, -9.73);
scene.add(seam);
}
const ceilingMaterial = new THREE.MeshBasicMaterial({
color: 0xb7e7ef,
transparent: true,
opacity: 0.68
});
for (const x of [-6, 0, 6]) {
const lightBar = new THREE.Mesh(new THREE.BoxGeometry(3.4, 0.045, 0.12), ceilingMaterial);
lightBar.position.set(x, 8.5, -1.4);
scene.add(lightBar);
}
const accentColors = {
spiral: "#74e5ee",
irregular: "#b99cff",
elliptical: "#ffb18f",
barred: "#ffd28b",
lenticular: "#a9b9ff"
};
function buildExhibit(category) {
const root = new THREE.Group();
root.position.copy(category.position);
root.rotation.copy(category.rotation);
scene.add(root);
const random = randomGenerator(category.seed);
if (category.id === "spiral") buildSpiral(root, category, random);
if (category.id === "irregular") buildIrregular(root, category, random);
if (category.id === "elliptical") buildElliptical(root, category, random);
if (category.id === "barred") buildBarred(root, category, random);
if (category.id === "lenticular") buildLenticular(root, category, random);
const layers = new Map();
root.traverse(object => {
if (object.isInstancedMesh && object.userData.categoryId === category.id) {
const key = object.parent.name;
layers.set(key, {
group: object.parent,
mesh: object,
material: object.material,
baseOpacity: object.material.opacity
});
}
});
models.set(category.id, {
root,
layers,
baseRotation: category.rotation.clone(),
spin: 0
});
const pedestal = new THREE.Group();
pedestal.position.set(category.position.x, 0, category.position.z);
scene.add(pedestal);
const base = new THREE.Mesh(
new THREE.BoxGeometry(3.45, 0.34, 3.45),
new THREE.MeshStandardMaterial({
color: 0x111821,
roughness: 0.72,
metalness: 0.28
})
);
base.position.y = 0.17;
base.castShadow = true;
base.receiveShadow = true;
pedestal.add(base);
const top = new THREE.Mesh(
new THREE.BoxGeometry(2.8, 0.18, 2.8),
new THREE.MeshStandardMaterial({
color: 0x171f29,
roughness: 0.58,
metalness: 0.35
})
);
top.position.y = 0.43;
top.castShadow = true;
top.receiveShadow = true;
top.userData.categoryId = category.id;
pedestal.add(top);
raycastMeshes.push(top);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x364957,
transparent: true,
opacity: 0.8
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(2.83, 0.19, 2.83)),
edgeMaterial
);
edges.position.y = 0.43;
pedestal.add(edges);
const beamMaterial = new THREE.MeshBasicMaterial({
color: 0x6adbe5,
transparent: true,
opacity: 0.035,
depthWrite: false
});
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 1.2, 3.25, 24, 1, true),
beamMaterial
);
beam.position.y = 2.05;
pedestal.add(beam);
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(2.45, 0.57),
new THREE.MeshBasicMaterial({
map: makePlaqueTexture(category.name, accentColors[category.id]),
transparent: true,
side: THREE.DoubleSide
})
);
plaque.position.set(0, 0.77, 1.74);
pedestal.add(plaque);
const light = new THREE.PointLight(
new THREE.Color(accentColors[category.id]),
0.7,
6,
2
);
light.position.set(0, 2.4, 0);
pedestal.add(light);
models.get(category.id).pedestal = {
edges,
edgeMaterial,
light
};
}
categories.forEach(buildExhibit);
for (const category of categories) {
const button = document.createElement("button");
button.className = "category-card";
button.type = "button";
button.dataset.id = category.id;
button.setAttribute("aria-label", `Inspect ${category.name}`);
button.innerHTML = `
<span class="glyph ${category.id}" aria-hidden="true">
<i></i><i></i><i></i><i></i><i></i><i></i>
</span>
<span>
<strong>${category.name}</strong>
<p>${category.description}</p>
</span>
`;
categoryList.appendChild(button);
const label = document.createElement("div");
label.className = "exhibit-label";
label.innerHTML = `
<strong>${category.name}</strong>
<span>${category.short}</span>
`;
labelsLayer.appendChild(label);
labelElements.set(category.id, label);
}
let selectedId = null;
let showLabels = true;
let turntable = false;
const desiredTarget = new THREE.Vector3(0, 3.5, 0);
const currentTarget = desiredTarget.clone();
let desiredAzimuth = -0.16;
let currentAzimuth = desiredAzimuth;
let desiredElevation = 0.43;
let currentElevation = desiredElevation;
let desiredDistance = 17.2;
let currentDistance = desiredDistance;
const azimuthSlider = document.getElementById("azimuthSlider");
const elevationSlider = document.getElementById("elevationSlider");
const distanceSlider = document.getElementById("distanceSlider");
const azimuthValue = document.getElementById("azimuthValue");
const elevationValue = document.getElementById("elevationValue");
const distanceValue = document.getElementById("distanceValue");
const spinButton = document.getElementById("spinButton");
const resetButton = document.getElementById("resetButton");
const overviewButton = document.getElementById("overviewButton");
const labelsButton = document.getElementById("labelsButton");
const helpButton = document.getElementById("helpButton");
const helpModal = document.getElementById("helpModal");
const closeHelpButton = document.getElementById("closeHelpButton");
const inspectionKicker = document.getElementById("inspectionKicker");
const inspectionTitle = document.getElementById("inspectionTitle");
const inspectionText = document.getElementById("inspectionText");
const inspectionMeta = document.getElementById("inspectionMeta");
const controlsTitle = document.getElementById("controlsTitle");
function refreshEmphasis() {
for (const category of categories) {
const model = models.get(category.id);
const isFocused = selectedId === category.id;
const isOverview = selectedId === null;
for (const layer of model.layers.values()) {
const opacity = (!isFocused && !isOverview)
? layer.baseOpacity * 0.28
: layer.baseOpacity;
layer.material.opacity = opacity;
layer.material.transparent = opacity < 0.99;
layer.material.depthWrite = opacity > 0.55;
layer.material.emissiveIntensity = isFocused || isOverview ? 0.13 : 0.035;
}
model.pedestal.light.intensity = isFocused ? 2.1 : isOverview ? 0.75 : 0.32;
model.pedestal.edgeMaterial.color.set(
isFocused ? accentColors[category.id] : 0x364957
);
model.pedestal.edgeMaterial.opacity = isFocused ? 1 : 0.68;
}
}
function buildLayerButtons(category) {
layerControls.innerHTML = "";
for (const [key, title] of category.parts) {
const button = document.createElement("button");
button.className = "layer-chip";
button.type = "button";
button.textContent = title;
button.setAttribute("aria-pressed", "true");
button.addEventListener("click", () => {
const layer = models.get(category.id).layers.get(key);
if (!layer) return;
const visible = !layer.group.visible;
layer.group.visible = visible;
button.setAttribute("aria-pressed", String(visible));
});
layerControls.appendChild(button);
}
}
function selectCategory(id) {
const category = categoryById.get(id);
if (!category) return;
selectedId = id;
desiredTarget.copy(category.position);
desiredDistance = window.innerWidth < 760 ? 10.2 : 8.6;
desiredElevation = 0.24;
document.querySelectorAll(".category-card").forEach(card => {
card.classList.toggle("active", card.dataset.id === id);
});
for (const [categoryId, label] of labelElements) {
label.classList.toggle("active", categoryId === id);
}
inspectionKicker.textContent = "Selected category";
inspectionTitle.textContent = category.name;
inspectionText.textContent = category.description + " " + category.detail;
inspectionMeta.textContent = category.detail;
controlsTitle.textContent = `${category.name} / Components`;
spinButton.disabled = false;
buildLayerButtons(category);
refreshEmphasis();
}
function showOverview() {
selectedId = null;
desiredTarget.set(0, 3.55, 0);
desiredAzimuth = -0.16;
desiredElevation = 0.43;
desiredDistance = 17.2;
document.querySelectorAll(".category-card").forEach(card => {
card.classList.remove("active");
});
for (const label of labelElements.values()) {
label.classList.remove("active");
}
inspectionKicker.textContent = "Gallery overview";
inspectionTitle.textContent = "The form atlas";
inspectionText.textContent =
"A side-by-side collection of schematic galactic arrangements. " +
"The categories describe visible structure rather than stages in a sequence.";
inspectionMeta.textContent =
"Drag to orbit · wheel or pinch to zoom · select any exhibit";
controlsTitle.textContent = "Gallery / Orbit";
spinButton.disabled = true;
layerControls.innerHTML = `
<button class="layer-chip" type="button" disabled>
Select an exhibit to toggle components
</button>
`;
refreshEmphasis();
}
categoryList.addEventListener("click", event => {
const card = event.target.closest(".category-card");
if (card) selectCategory(card.dataset.id);
});
overviewButton.addEventListener("click", showOverview);
labelsButton.addEventListener("click", () => {
showLabels = !showLabels;
labelsButton.setAttribute("aria-pressed", String(showLabels));
labelsLayer.hidden = !showLabels;
});
spinButton.addEventListener("click", () => {
turntable = !turntable;
spinButton.setAttribute("aria-pressed", String(turntable));
});
resetButton.addEventListener("click", () => {
if (selectedId) {
const category = categoryById.get(selectedId);
desiredTarget.copy(category.position);
desiredAzimuth = -0.16;
desiredElevation = 0.24;
desiredDistance = window.innerWidth < 760 ? 10.2 : 8.6;
} else {
desiredTarget.set(0, 3.55, 0);
desiredAzimuth = -0.16;
desiredElevation = 0.43;
desiredDistance = 17.2;
}
});
helpButton.addEventListener("click", () => {
helpModal.hidden = false;
closeHelpButton.focus();
});
closeHelpButton.addEventListener("click", () => {
helpModal.hidden = true;
helpButton.focus();
});
helpModal.addEventListener("click", event => {
if (event.target === helpModal) {
helpModal.hidden = true;
helpButton.focus();
}
});
azimuthSlider.addEventListener("input", () => {
desiredAzimuth = THREE.MathUtils.degToRad(Number(azimuthSlider.value));
});
elevationSlider.addEventListener("input", () => {
desiredElevation = THREE.MathUtils.degToRad(Number(elevationSlider.value));
});
distanceSlider.addEventListener("input", () => {
desiredDistance = Number(distanceSlider.value);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointers = new Map();
let dragMoved = false;
let lastPinchDistance = 0;
function setPointerFromEvent(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickCategory(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(raycastMeshes, false);
return hits.length ? hits[0].object.userData.categoryId : null;
}
function panView(deltaX, deltaY) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = desiredDistance * 0.00125;
desiredTarget.addScaledVector(right, -deltaX * scale);
desiredTarget.addScaledVector(up, deltaY * scale);
desiredTarget.x = THREE.MathUtils.clamp(desiredTarget.x, -9, 9);
desiredTarget.y = THREE.MathUtils.clamp(desiredTarget.y, 0.5, 8);
desiredTarget.z = THREE.MathUtils.clamp(desiredTarget.z, -7, 7);
}
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
dragMoved = false;
renderer.domElement.style.cursor = "grabbing";
if (pointers.size === 2) {
const values = [...pointers.values()];
lastPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointers.has(event.pointerId)) {
const id = pickCategory(event);
renderer.domElement.style.cursor = id ? "pointer" : "grab";
return;
}
const old = pointers.get(event.pointerId);
const deltaX = event.clientX - old.x;
const deltaY = event.clientY - old.y;
if (Math.abs(deltaX) + Math.abs(deltaY) > 1) {
dragMoved = true;
}
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
if (event.button === 2 || event.shiftKey) {
panView(deltaX, deltaY);
} else {
desiredAzimuth -= deltaX * 0.006;
desiredElevation = THREE.MathUtils.clamp(
desiredElevation + deltaY * 0.0045,
THREE.MathUtils.degToRad(-70),
THREE.MathUtils.degToRad(78)
);
}
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
desiredDistance = THREE.MathUtils.clamp(
desiredDistance * (lastPinchDistance / distance),
4.5,
24
);
}
lastPinchDistance = distance;
}
});
renderer.domElement.addEventListener("pointerup", event => {
const wasTap = !dragMoved && pointers.size === 1 && event.button === 0;
pointers.delete(event.pointerId);
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (wasTap) {
const id = pickCategory(event);
if (id) selectCategory(id);
}
if (pointers.size === 1) {
lastPinchDistance = 0;
}
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener("pointercancel", event => {
pointers.delete(event.pointerId);
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredDistance = THREE.MathUtils.clamp(
desiredDistance * Math.exp(event.deltaY * 0.001),
4.5,
24
);
},
{ passive: false }
);
window.addEventListener("keydown", event => {
if (event.key === "Escape") {
helpModal.hidden = true;
}
if (event.target instanceof HTMLInputElement) return;
if (event.key.toLowerCase() === "o") {
showOverview();
}
const index = Number(event.key);
if (index >= 1 && index <= categories.length) {
selectCategory(categories[index - 1].id);
}
});
function shortestAngleDelta(from, to) {
let delta = (to - from) % (Math.PI * 2);
if (delta > Math.PI) delta -= Math.PI * 2;
if (delta < -Math.PI) delta += Math.PI * 2;
return delta;
}
function normalizeDegrees(radians) {
return ((THREE.MathUtils.radToDeg(radians) + 180) % 360 + 360) % 360 - 180;
}
const projected = new THREE.Vector3();
const clock = new THREE.Clock();
function updateLabels() {
if (!showLabels) return;
for (const category of categories) {
const label = labelElements.get(category.id);
projected.set(
category.position.x,
category.position.y + 3.72,
category.position.z
);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
label.style.display = visible ? "block" : "none";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.style.left = `${x}px`;
label.style.top = `${y}px`;
}
}
}
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-delta * 5.4);
currentTarget.lerp(desiredTarget, damping);
currentAzimuth += shortestAngleDelta(currentAzimuth, desiredAzimuth) * damping;
currentElevation += (desiredElevation - currentElevation) * damping;
currentDistance += (desiredDistance - currentDistance) * damping;
const horizontal = currentDistance * Math.cos(currentElevation);
camera.position.set(
currentTarget.x + horizontal * Math.sin(currentAzimuth),
currentTarget.y + currentDistance * Math.sin(currentElevation),
currentTarget.z + horizontal * Math.cos(currentAzimuth)
);
camera.lookAt(currentTarget);
camera.updateMatrixWorld();
if (turntable && selectedId) {
const model = models.get(selectedId);
model.spin += delta * 0.18;
model.root.rotation.z = model.baseRotation.z + model.spin;
}
const azimuthDegrees = Math.round(normalizeDegrees(currentAzimuth));
const elevationDegrees = Math.round(THREE.MathUtils.radToDeg(currentElevation));
azimuthSlider.value = String(azimuthDegrees);
elevationSlider.value = String(elevationDegrees);
distanceSlider.value = currentDistance.toFixed(1);
azimuthValue.textContent = `${azimuthDegrees}°`;
elevationValue.textContent = `${elevationDegrees}°`;
distanceValue.textContent = currentDistance.toFixed(1);
updateLabels();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
});
showOverview();
animate();
</script>
</body>
</html>
```