Prompt specification
Build or customize the Three.js 3D scene "Planetary Walk Exhibition" 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: Planetary Walk Exhibition
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/planetary-walk-exhibition-x3763
Scene Description Prompt:
A voxel solar-system scale-model walk with inspectable distances and explicitly marked compressed sections. One HTML file using Three.js from cdnjs.
Working Three.js Starter (planetary-walk-exhibition-x3763):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Orrery — Compressed Solar-System Walk</title>
<style>
:root {
color-scheme: dark;
--bg: #030711;
--panel: rgba(8, 15, 29, 0.78);
--panel-solid: #0a1222;
--line: rgba(163, 196, 255, 0.18);
--text: #edf5ff;
--muted: #8da0bb;
--cyan: #59d9f5;
--purple: #aa8cff;
--orange: #f4ad58;
--pink: #ee6cab;
--accent: #ffd479;
}
* {
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 {
color: inherit;
font: inherit;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#app canvas {
display: block;
cursor: grab;
touch-action: none;
}
#app canvas.dragging {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.interactive,
.panel,
button {
pointer-events: auto;
}
.panel {
background:
linear-gradient(145deg, rgba(20, 33, 56, 0.86), rgba(6, 12, 25, 0.88));
border: 1px solid var(--line);
border-radius: 16px;
box-shadow:
0 22px 70px rgba(0, 0, 0, 0.34),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
}
.topbar {
position: absolute;
top: 18px;
left: 20px;
right: 20px;
display: grid;
grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr);
align-items: start;
gap: 16px;
}
.brand {
justify-self: start;
padding: 13px 16px 12px;
min-width: 270px;
}
.eyebrow {
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.brand h1 {
margin: 5px 0 2px;
font-size: 18px;
letter-spacing: 0.02em;
font-weight: 760;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.section-pill {
justify-self: center;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
border-radius: 999px;
background: rgba(5, 10, 21, 0.75);
border: 1px solid var(--line);
backdrop-filter: blur(14px);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.25);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 14px currentColor;
}
.top-actions {
justify-self: end;
display: flex;
gap: 8px;
padding: 7px;
}
.top-actions button,
.mini-button {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.045);
border-radius: 9px;
padding: 9px 11px;
color: #dceaff;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.07em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
.top-actions button:hover,
.mini-button:hover {
background: rgba(89, 217, 245, 0.13);
border-color: rgba(89, 217, 245, 0.45);
color: white;
}
.index-panel {
position: absolute;
top: 110px;
left: 20px;
width: 222px;
padding: 14px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.panel-heading h2 {
margin: 0;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel-heading span {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.target-list {
display: grid;
gap: 4px;
}
.target-button {
display: grid;
grid-template-columns: 13px 1fr auto;
align-items: center;
gap: 9px;
width: 100%;
padding: 7px 8px;
border: 1px solid transparent;
border-radius: 8px;
background: transparent;
color: #b9c8dc;
text-align: left;
cursor: pointer;
transition: 140ms ease;
}
.target-button:hover {
background: rgba(255, 255, 255, 0.055);
color: white;
}
.target-button.active {
border-color: rgba(89, 217, 245, 0.25);
background: rgba(89, 217, 245, 0.1);
color: white;
}
.planet-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--planet-color);
box-shadow: 0 0 10px color-mix(in srgb, var(--planet-color), transparent 40%);
}
.target-button span {
font-size: 11px;
font-weight: 650;
}
.target-button small {
color: #7185a2;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.index-note {
margin: 12px 2px 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #7388a4;
font-size: 9px;
line-height: 1.55;
}
.inspector {
position: absolute;
top: 110px;
right: 20px;
width: 340px;
max-height: calc(100vh - 260px);
overflow: auto;
padding: 17px;
scrollbar-width: thin;
scrollbar-color: rgba(130, 170, 220, 0.3) transparent;
}
.inspector.hidden {
display: none;
}
.close-button {
width: 27px;
height: 27px;
padding: 0;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.04);
color: #9eb1ca;
cursor: pointer;
}
.close-button:hover {
color: white;
border-color: rgba(255, 255, 255, 0.3);
}
.object-heading {
display: flex;
align-items: center;
gap: 12px;
margin: 3px 0 15px;
}
.object-orb {
position: relative;
flex: 0 0 auto;
width: 43px;
height: 43px;
border-radius: 50%;
background: var(--planet-color);
box-shadow:
inset -9px -6px 15px rgba(0, 0, 0, 0.4),
0 0 25px color-mix(in srgb, var(--planet-color), transparent 55%);
}
.object-orb::after {
content: "";
position: absolute;
inset: 5px;
border-radius: inherit;
opacity: 0.3;
background-image:
linear-gradient(90deg, transparent 48%, rgba(255,255,255,.24) 50%, transparent 52%),
linear-gradient(transparent 48%, rgba(255,255,255,.2) 50%, transparent 52%);
background-size: 11px 11px;
}
.object-heading h2 {
margin: 0;
font-size: 22px;
line-height: 1;
}
.object-heading p {
margin: 5px 0 0;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.stat-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.stat {
min-height: 74px;
padding: 10px;
border: 1px solid rgba(160, 195, 245, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.stat label {
display: block;
margin-bottom: 6px;
color: #8195b2;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.stat strong {
display: block;
font-size: 15px;
font-variant-numeric: tabular-nums;
}
.stat small {
display: block;
margin-top: 4px;
color: #7287a4;
font-size: 9px;
line-height: 1.3;
}
.comparison {
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
}
.comparison h3 {
margin: 0 0 11px;
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
color: #a9bbd3;
}
.bar-row {
margin: 9px 0;
}
.bar-label {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
color: #8095b1;
font-size: 9px;
}
.bar-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.055);
}
.bar-fill {
height: 100%;
min-width: 3px;
border-radius: inherit;
transition: width 400ms ease;
}
.bar-fill.actual {
background: linear-gradient(90deg, #6ca4ff, #9f7dff);
}
.bar-fill.model {
background: linear-gradient(90deg, #ffd06a, #ff8d61);
}
.comparison-note {
margin: 10px 0 0;
color: #6f84a1;
font-size: 8px;
line-height: 1.5;
}
.compression-note {
margin-top: 13px;
padding: 10px 11px;
border-left: 2px solid var(--section-color, var(--cyan));
border-radius: 0 8px 8px 0;
background: color-mix(in srgb, var(--section-color, var(--cyan)) 8%, transparent);
color: #a5b6cc;
font-size: 9px;
line-height: 1.55;
}
.inspector-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 14px;
}
.primary-button {
border: 1px solid rgba(255, 212, 121, 0.4);
border-radius: 9px;
padding: 10px 12px;
background: rgba(255, 212, 121, 0.13);
color: #ffe3a7;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
}
.primary-button:hover {
background: rgba(255, 212, 121, 0.23);
}
.position-hud {
position: absolute;
right: 20px;
bottom: 132px;
min-width: 190px;
padding: 10px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(4, 9, 19, 0.75);
backdrop-filter: blur(12px);
color: #91a5c0;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.position-hud strong {
color: white;
font-size: 13px;
}
.position-hud span {
color: var(--muted);
}
.legend {
position: absolute;
left: 20px;
bottom: 20px;
width: min(560px, calc(100vw - 40px));
padding: 12px 14px;
}
.legend-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
.legend-title strong {
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-title span {
color: #7186a3;
font-size: 8px;
text-align: right;
}
.legend-sections {
display: grid;
grid-template-columns: 0.72fr 1.35fr 1.15fr 1fr;
gap: 4px;
}
.legend-section {
position: relative;
min-width: 0;
overflow: hidden;
padding: 8px;
border: 1px solid color-mix(in srgb, var(--section-color) 25%, transparent);
border-radius: 8px;
background: color-mix(in srgb, var(--section-color) 8%, transparent);
text-align: left;
cursor: pointer;
}
.legend-section::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--section-color);
}
.legend-section:hover {
background: color-mix(in srgb, var(--section-color) 15%, transparent);
}
.legend-section strong {
display: block;
overflow: hidden;
color: white;
font-size: 8px;
letter-spacing: 0.07em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.legend-section span {
display: block;
margin-top: 4px;
color: #8da0bb;
font-size: 7px;
line-height: 1.35;
}
.help-bar {
position: absolute;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
padding: 9px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(4, 9, 19, 0.7);
backdrop-filter: blur(12px);
color: #8398b5;
font-size: 9px;
white-space: nowrap;
}
kbd {
display: inline-grid;
min-width: 19px;
height: 19px;
place-items: center;
margin: 0 2px;
padding: 0 5px;
border: 1px solid rgba(180, 210, 255, 0.22);
border-bottom-color: rgba(180, 210, 255, 0.42);
border-radius: 5px;
background: rgba(255, 255, 255, 0.06);
color: #dcecff;
font: 700 8px inherit;
}
.crosshair {
position: absolute;
left: 50%;
top: 50%;
width: 16px;
height: 16px;
transform: translate(-50%, -50%);
opacity: 0.48;
}
.crosshair::before,
.crosshair::after {
content: "";
position: absolute;
background: rgba(224, 241, 255, 0.72);
}
.crosshair::before {
left: 7px;
top: 1px;
width: 2px;
height: 14px;
}
.crosshair::after {
top: 7px;
left: 1px;
height: 2px;
width: 14px;
}
.toast {
position: absolute;
left: 50%;
top: 85px;
transform: translate(-50%, -12px);
padding: 9px 14px;
border: 1px solid rgba(255, 212, 121, 0.25);
border-radius: 999px;
background: rgba(10, 16, 30, 0.88);
color: #ffe2a5;
font-size: 10px;
opacity: 0;
transition: 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.touch-controls {
display: none;
position: absolute;
left: 16px;
bottom: 145px;
grid-template-columns: repeat(3, 42px);
grid-template-rows: repeat(2, 42px);
gap: 5px;
}
.touch-controls button {
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(8, 16, 31, 0.75);
color: white;
touch-action: none;
}
.touch-controls button:first-child {
grid-column: 2;
}
.touch-controls button:nth-child(2) {
grid-column: 1;
grid-row: 2;
}
.touch-controls button:nth-child(3) {
grid-column: 2;
grid-row: 2;
}
.touch-controls button:nth-child(4) {
grid-column: 3;
grid-row: 2;
}
@media (max-width: 1050px) {
.help-bar {
display: none;
}
.index-panel {
width: 190px;
}
.inspector {
width: 310px;
}
}
@media (max-width: 760px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
grid-template-columns: 1fr auto;
}
.brand {
min-width: 0;
padding: 10px 12px;
}
.brand h1 {
font-size: 14px;
}
.brand p,
.section-pill {
display: none;
}
.top-actions {
grid-column: 2;
}
.index-panel {
top: 80px;
left: 10px;
width: 156px;
max-height: 42vh;
overflow: auto;
}
.index-note {
display: none;
}
.target-button {
grid-template-columns: 11px 1fr;
}
.target-button small {
display: none;
}
.inspector {
top: auto;
right: 10px;
bottom: 116px;
width: min(330px, calc(100vw - 20px));
max-height: 58vh;
}
.legend {
left: 10px;
bottom: 10px;
width: calc(100vw - 20px);
}
.legend-title span {
display: none;
}
.legend-section {
padding: 7px 5px;
}
.legend-section span {
font-size: 6px;
}
.position-hud {
display: none;
}
}
@media (pointer: coarse) {
.touch-controls {
display: grid;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="ui">
<header class="topbar">
<div class="brand panel interactive">
<div class="eyebrow">Solar-System Scale Model / 01</div>
<h1>Voxel Orrery Walk</h1>
<p>A measured radial corridor with explicitly compressed orbital sections.</p>
</div>
<div class="section-pill">
<span class="section-dot" id="sectionDot"></span>
<span id="currentSection">Inner system</span>
</div>
<nav class="top-actions panel interactive" aria-label="Camera controls">
<button id="overviewButton" title="Show the entire compressed corridor">Overview</button>
<button id="resetButton" title="Return to the opening view">Reset</button>
</nav>
</header>
<aside class="index-panel panel interactive">
<div class="panel-heading">
<h2>World Index</h2>
<span>True distance</span>
</div>
<div class="target-list" id="targetList"></div>
<p class="index-note">
Select a body to inspect its true and displayed distance.
Double-click a body in the scene to fly to it.
</p>
</aside>
<aside class="inspector panel interactive hidden" id="inspector">
<div class="panel-heading">
<h2>Object Inspector</h2>
<button class="close-button" id="closeInspector" aria-label="Close inspector">×</button>
</div>
<div id="inspectorContent"></div>
</aside>
<div class="position-hud">
<div>MODEL POSITION</div>
<strong id="modelPosition">0.0 m</strong>
<span id="truePosition">≈ 0.00 AU from Sun</span>
</div>
<section class="legend panel interactive">
<div class="legend-title">
<strong>Marked orbital compression</strong>
<span>Click a section to visit its boundary</span>
</div>
<div class="legend-sections" id="legendSections"></div>
</section>
<div class="help-bar">
<kbd>W</kbd><kbd>A</kbd><kbd>S</kbd><kbd>D</kbd> walk
·
drag to look
·
<kbd>Shift</kbd> sprint
·
<kbd>F</kbd> focus
·
<kbd>O</kbd> overview
</div>
<div class="crosshair"></div>
<div class="toast" id="toast"></div>
<div class="touch-controls" aria-label="Touch movement controls">
<button data-key="KeyW" aria-label="Forward">▲</button>
<button data-key="KeyA" aria-label="Left">◀</button>
<button data-key="KeyS" aria-label="Backward">▼</button>
<button data-key="KeyD" aria-label="Right">▶</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";
// -------------------------------------------------------------------------
// Data and scale model
// -------------------------------------------------------------------------
const AU_KM = 149_597_870.7;
const INNER_SCALE = 12; // Model metres per AU in the reference inner section.
// Each section uses a different metres-per-AU scale. The boundaries and
// compression ratios are shown both in the scene and in the interface.
const SECTIONS = [
{
id: "inner",
label: "Inner system",
shortLabel: "Inner",
startAU: 0,
endAU: 1.6,
scale: 12,
color: "#59d9f5",
ratio: 1,
description: "Reference spacing. Mercury through Mars remain relatively legible."
},
{
id: "main",
label: "Main-system belt",
shortLabel: "Main belt",
startAU: 1.6,
endAU: 30,
scale: 4,
color: "#aa8cff",
ratio: 3,
description: "Orbital spacing is compressed to 4 model metres per AU."
},
{
id: "outer",
label: "Outer system",
shortLabel: "Outer",
startAU: 30,
endAU: 140,
scale: 2.2,
color: "#f4ad58",
ratio: 5.45,
description: "Orbital spacing is compressed to 2.2 model metres per AU."
},
{
id: "deep",
label: "Deep-space arc",
shortLabel: "Deep space",
startAU: 140,
endAU: 700,
scale: 1.2,
color: "#ee6cab",
ratio: 10,
description: "The most compressed section: 1.2 model metres per true AU."
}
];
const PLANETS = [
{
id: "sun",
name: "Sun",
kind: "G2V main-sequence star",
color: "#ffbd45",
au: 0,
radiusKm: 696340,
displayRadius: 6.3,
resolution: 18,
spin: 0.035,
note: "The corridor origin."
},
{
id: "mercury",
name: "Mercury",
kind: "Terrestrial planet",
color: "#a8a19a",
au: 0.3871,
radiusKm: 2439.7,
displayRadius: 1.35,
resolution: 10,
spin: 0.035,
note: "The smallest planet and the closest exhibit body to the Sun."
},
{
id: "venus",
name: "Venus",
kind: "Terrestrial planet",
color: "#d9a15c",
au: 0.7233,
radiusKm: 6051.8,
displayRadius: 2,
resolution: 11,
spin: -0.025,
note: "A dense, cloud-wrapped terrestrial world."
},
{
id: "earth",
name: "Earth",
kind: "Terrestrial planet",
color: "#2f83d7",
au: 1,
radiusKm: 6371,
displayRadius: 2.1,
resolution: 12,
spin: 0.09,
note: "The one-AU reference point of the inner-system scale."
},
{
id: "mars",
name: "Mars",
kind: "Terrestrial planet",
color: "#c65b3b",
au: 1.5237,
radiusKm: 3389.5,
displayRadius: 1.6,
resolution: 10,
spin: 0.08,
note: "The outer boundary of the uncompressed inner-system section."
},
{
id: "jupiter",
name: "Jupiter",
kind: "Gas giant",
color: "#c99a6d",
au: 5.2026,
radiusKm: 69911,
displayRadius: 3.8,
resolution: 16,
spin: 0.16,
note: "The largest planet begins the strongly compressed main-system belt."
},
{
id: "saturn",
name: "Saturn",
kind: "Gas giant",
color: "#d8bd7d",
au: 9.5367,
radiusKm: 58232,
displayRadius: 3.7,
resolution: 16,
spin: 0.14,
note: "Its voxel ring is an exhibit feature, not a distance marker."
},
{
id: "uranus",
name: "Uranus",
kind: "Ice giant",
color: "#78d6d4",
au: 19.191,
radiusKm: 25362,
displayRadius: 3,
resolution: 14,
spin: -0.1,
note: "An ice giant located in the middle of the main compressed belt."
},
{
id: "neptune",
name: "Neptune",
kind: "Ice giant",
color: "#466ce0",
au: 30.069,
radiusKm: 24622,
displayRadius: 3,
resolution: 14,
spin: 0.11,
note: "Nearly marks the boundary between the main and outer sections."
},
{
id: "pluto",
name: "Pluto",
kind: "Dwarf planet",
color: "#b9a08b",
au: 39.482,
radiusKm: 1188.3,
displayRadius: 1.25,
resolution: 10,
spin: 0.045,
note: "The first listed exhibit beyond Neptune."
},
{
id: "eris",
name: "Eris",
kind: "Dwarf planet",
color: "#d7d4c8",
au: 67.781,
radiusKm: 1163,
displayRadius: 1.25,
resolution: 10,
spin: 0.04,
note: "A distant-body exhibit in the outer compressed section."
},
{
id: "sedna",
name: "Sedna",
kind: "Dwarf-planet candidate",
color: "#b95c48",
au: 506.8,
radiusKm: 498,
displayRadius: 1.2,
resolution: 10,
spin: 0.025,
note: "Its location demonstrates the deepest radial compression."
}
];
const planetById = new Map(PLANETS.map((planet) => [planet.id, planet]));
const pickMeshes = [];
const spinningMeshes = [];
const planetGroups = new Map();
let sectionModelStart = 0;
for (const section of SECTIONS) {
section.modelStart = sectionModelStart;
section.modelEnd = sectionModelStart + (section.endAU - section.startAU) * section.scale;
sectionModelStart = section.modelEnd;
}
function modelPosition(au) {
let position = 0;
for (const section of SECTIONS) {
if (au <= section.endAU) {
position += (au - section.startAU) * section.scale;
break;
}
position += (section.endAU - section.startAU) * section.scale;
}
return position;
}
function truePosition(modelX) {
if (modelX <= 0) return 0;
for (const section of SECTIONS) {
if (modelX <= section.modelEnd) {
return section.startAU + (modelX - section.modelStart) / section.scale;
}
}
return SECTIONS.at(-1).endAU;
}
function sectionForAU(au) {
return SECTIONS.find((section) => au <= section.endAU) ?? SECTIONS.at(-1);
}
function sectionForModel(modelX) {
return SECTIONS.find((section) => modelX <= section.modelEnd) ?? SECTIONS.at(-1);
}
for (const planet of PLANETS) {
planet.modelX = modelPosition(planet.au);
planet.section = sectionForAU(planet.au);
}
const MAX_TRUE_AU = 506.8;
const MAX_MODEL_X = modelPosition(MAX_TRUE_AU);
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const app = document.querySelector("#app");
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.18;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x030711);
scene.fog = new THREE.Fog(0x030711, 85, 620);
const camera = new THREE.PerspectiveCamera(
62,
window.innerWidth / window.innerHeight,
0.08,
1800
);
camera.position.set(-28, 9, 22);
let yaw = 1.04;
let pitch = -0.075;
camera.rotation.set(pitch, yaw, 0, "YXZ");
const hemiLight = new THREE.HemisphereLight(0x9fc5ff, 0x241026, 1.75);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.25);
keyLight.position.set(-40, 70, 35);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x597dff, 1.0);
rimLight.position.set(80, 20, -60);
scene.add(rimLight);
const sunLight = new THREE.PointLight(0xffb74f, 900, 135, 1.4);
sunLight.position.set(0, 8, 0);
scene.add(sunLight);
// -------------------------------------------------------------------------
// Shared helpers
// -------------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function hashNoise(x, y, z, seed = 0) {
const value = Math.sin(
x * 12.9898 +
y * 78.233 +
z * 37.719 +
seed * 19.193
) * 43758.5453;
return value - Math.floor(value);
}
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.arcTo(x + width, y, x + width, y + height, r);
context.arcTo(x + width, y + height, x, y + height, r);
context.arcTo(x, y + height, x, y, r);
context.arcTo(x, y, x + width, y, r);
context.closePath();
}
function makeLabel(title, subtitle, color = "#dcecff", width = 13) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 10, 12, 1004, 232, 34);
context.fillStyle = "rgba(4, 10, 23, 0.82)";
context.fill();
context.lineWidth = 5;
context.strokeStyle = color;
context.globalAlpha = 0.72;
context.stroke();
context.globalAlpha = 1;
context.fillStyle = color;
context.fillRect(36, 48, 8, 158);
context.fillStyle = "#f4f8ff";
context.font = "700 66px system-ui, sans-serif";
context.textBaseline = "middle";
context.fillText(title.toUpperCase(), 69, 92);
context.fillStyle = "#9eb3cf";
context.font = "500 33px system-ui, sans-serif";
context.fillText(subtitle, 69, 167);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
depthTest: true
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 0.25, 1);
sprite.userData.aspect = 4;
return sprite;
}
function makeGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(128, 128, 3, 128, 128, 128);
gradient.addColorStop(0, "rgba(255,244,183,1)");
gradient.addColorStop(0.16, "rgba(255,194,75,0.7)");
gradient.addColorStop(0.48, "rgba(255,118,35,0.16)");
gradient.addColorStop(1, "rgba(255,80,0,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
return new THREE.CanvasTexture(canvas);
}
// -------------------------------------------------------------------------
// Floor, distance corridor, section gates, and grid
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.BoxGeometry(1120, 0.25, 46),
new THREE.MeshStandardMaterial({
color: 0x07101d,
roughness: 0.96,
metalness: 0.05
})
);
floor.position.set(510, -0.14, 0);
scene.add(floor);
for (const section of SECTIONS) {
const length = section.modelEnd - section.modelStart;
const band = new THREE.Mesh(
new THREE.PlaneGeometry(length, 38),
new THREE.MeshBasicMaterial({
color: new THREE.Color(section.color),
transparent: true,
opacity: 0.027,
depthWrite: false
})
);
band.rotation.x = -Math.PI / 2;
band.position.set(
(section.modelStart + section.modelEnd) / 2,
0.015,
0
);
scene.add(band);
const boundaryX = section.modelEnd;
const isLast = section === SECTIONS.at(-1);
if (!isLast || section.id === "deep") {
const gate = new THREE.Group();
gate.position.x = boundaryX;
const postGeometry = new THREE.BoxGeometry(0.18, 8.5, 0.18);
const postMaterial = new THREE.MeshBasicMaterial({
color: new THREE.Color(section.color),
transparent: true,
opacity: 0.72
});
for (const z of [-7.5, 7.5]) {
const post = new THREE.Mesh(postGeometry, postMaterial);
post.position.set(0, 4.25, z);
gate.add(post);
}
const header = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.18, 15),
postMaterial
);
header.position.y = 8.5;
gate.add(header);
const curtain = new THREE.Mesh(
new THREE.PlaneGeometry(15, 8.5),
new THREE.MeshBasicMaterial({
color: new THREE.Color(section.color),
transparent: true,
opacity: 0.025,
side: THREE.DoubleSide,
depthWrite: false
})
);
curtain.position.y = 4.25;
gate.add(curtain);
const nextSection = SECTIONS[SECTIONS.indexOf(section) + 1];
const subtitle = nextSection
? `${section.endAU} AU boundary · ${section.scale} m/AU inside`
: `${section.startAU}+ AU · ${section.scale} m/AU`;
const label = makeLabel(
`${section.shortLabel} / ${section.ratio}×`,
subtitle,
section.color,
15
);
label.position.set(0, 10.4, -7.5);
gate.add(label);
scene.add(gate);
}
}
function createGrid() {
const positions = [];
const startX = -50;
const endX = 1050;
const halfDepth = 23;
for (let x = startX; x <= endX; x += 10) {
positions.push(x, 0.035, -halfDepth, x, 0.035, halfDepth);
}
for (let z = -halfDepth; z <= halfDepth; z += 5) {
positions.push(startX, 0.035, z, endX, 0.035, z);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
const material = new THREE.LineBasicMaterial({
color: 0x3d5a7c,
transparent: true,
opacity: 0.16
});
scene.add(new THREE.LineSegments(geometry, material));
}
createGrid();
const rail = new THREE.Mesh(
new THREE.BoxGeometry(1070, 0.055, 0.055),
new THREE.MeshBasicMaterial({
color: 0x7ecfff,
transparent: true,
opacity: 0.42
})
);
rail.position.set(495, 0.1, -9.5);
scene.add(rail);
const startMarker = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.5, 20),
new THREE.MeshBasicMaterial({ color: 0x59d9f5 })
);
startMarker.position.set(0, 0.25, 0);
scene.add(startMarker);
// -------------------------------------------------------------------------
// Starfield
// -------------------------------------------------------------------------
function createStars() {
const count = 1800;
const positions = new Float32Array(count * 3);
const colors = new Float32Array(count * 3);
for (let i = 0; i < count; i++) {
const radius = 720 + Math.random() * 560;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
positions[i * 3] = radius * Math.sin(phi) * Math.cos(theta);
positions[i * 3 + 1] = radius * Math.cos(phi) * 0.75 + 120;
positions[i * 3 + 2] = radius * Math.sin(phi) * Math.sin(theta);
const brightness = 0.45 + Math.random() * 0.55;
colors[i * 3] = brightness * 0.8;
colors[i * 3 + 1] = brightness * 0.9;
colors[i * 3 + 2] = brightness;
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(positions, 3));
geometry.setAttribute("color", new THREE.BufferAttribute(colors, 3));
const material = new THREE.PointsMaterial({
size: 1.25,
sizeAttenuation: false,
vertexColors: true,
transparent: true,
opacity: 0.78
});
const stars = new THREE.Points(geometry, material);
scene.add(stars);
return stars;
}
const stars = createStars();
// -------------------------------------------------------------------------
// Voxel planet construction
// -------------------------------------------------------------------------
function planetVoxelColor(planet, nx, ny, nz, noise) {
const color = new THREE.Color(planet.color);
if (planet.id === "earth") {
const landSignal =
Math.sin(nx * 6.2 + planet.id.length) * 0.38 +
Math.sin(nz * 7.4 - ny * 2.1) * 0.28 +
(noise - 0.5) * 0.85;
if (landSignal > 0.12) {
color.set(noise > 0.67 ? "#8f9b54" : "#34784a");
if (ny > 0.72) color.set("#dce7df");
} else {
color.set(noise > 0.8 ? "#347fc2" : "#225ca4");
}
} else if (planet.id === "jupiter") {
const band = Math.sin(ny * 17 + Math.sin(nx * 5) * 0.8);
color.set(band > 0.35 ? "#ead4b5" : band < -0.45 ? "#9c6849" : "#c79568");
const redSpot =
Math.abs(nx - 0.34) < 0.19 &&
Math.abs(ny + 0.17) < 0.12 &&
Math.abs(nz - 0.48) < 0.26;
if (redSpot) color.set("#ad5c3e");
} else if (planet.id === "saturn") {
const band = Math.sin(ny * 20 + noise * 0.7);
color.set(band > 0.25 ? "#ead9a7" : "#bfa36b");
} else if (planet.id === "uranus") {
color.set(ny > 0.4 ? "#a4e4df" : "#65c6c7");
} else if (planet.id === "neptune") {
color.set(noise > 0.78 ? "#7997ed" : "#3458bb");
} else if (planet.id === "sun") {
color.set(
noise > 0.72
? "#ffe28b"
: noise > 0.42
? "#ffc54f"
: "#f39925"
);
} else {
color.offsetHSL(
(noise - 0.5) * 0.025,
(noise - 0.5) * 0.11,
(noise - 0.5) * 0.15
);
}
return color;
}
function createVoxelSphere(planet) {
const radius = planet.displayRadius;
const resolution = planet.resolution;
const step = (radius * 2) / resolution;
const positions = [];
for (let ix = 0; ix < resolution; ix++) {
const x = -radius + (ix + 0.5) * step;
for (let iy = 0; iy < resolution; iy++) {
const y = -radius + (iy + 0.5) * step;
for (let iz = 0; iz < resolution; iz++) {
const z = -radius + (iz + 0.5) * step;
const distance = Math.sqrt(x * x + y * y + z * z);
if (distance <= radius) {
positions.push({ x, y, z, ix, iy, iz });
}
}
}
}
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: planet.id === "sun" ? 0.66 : 0.88,
metalness: 0,
flatShading: true,
emissive: planet.id === "sun" ? 0x6f2700 : 0x000000,
emissiveIntensity: planet.id === "sun" ? 0.72 : 0
});
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
positions.length
);
const dummy = new THREE.Object3D();
positions.forEach((position, index) => {
dummy.position.set(position.x, position.y, position.z);
dummy.scale.setScalar(step * 1.025);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
const nx = position.x / radius;
const ny = position.y / radius;
const nz = position.z / radius;
const noise = hashNoise(
position.ix,
position.iy,
position.iz,
planet.id.length
);
const color = planetVoxelColor(planet, nx, ny, nz, noise);
mesh.setColorAt(index, color);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
mesh.userData.planetId = planet.id;
return mesh;
}
function createSaturnRing(planet) {
const count = 280;
const material = new THREE.MeshStandardMaterial({
color: 0xd7c28b,
vertexColors: true,
roughness: 0.9,
flatShading: true
});
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
count
);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
const band = i % 7;
const radius = planet.displayRadius * (1.42 + band * 0.12);
const size = planet.displayRadius * 0.09;
dummy.position.set(
Math.cos(angle) * radius,
(hashNoise(i, 1, 2, 8) - 0.5) * 0.08,
Math.sin(angle) * radius * 0.72
);
dummy.scale.set(size * 1.6, size * 0.35, size);
dummy.rotation.y = -angle;
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
color.set(band === 0 || band === 5 ? "#a88e5d" : "#e0ca92");
mesh.setColorAt(i, color);
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.computeBoundingSphere();
return mesh;
}
function createPedestal(planet) {
const group = new THREE.Group();
const radius = planet.displayRadius;
const base = new THREE.Mesh(
new THREE.BoxGeometry(radius * 2.25, 0.22, radius * 2.25),
new THREE.MeshStandardMaterial({
color: 0x142136,
roughness: 0.78,
metalness: 0.15
})
);
base.position.y = 0.18;
group.add(base);
const stemHeight = Math.max(0.65, radius * 0.25);
const stem = new THREE.Mesh(
new THREE.BoxGeometry(0.12, stemHeight, 0.12),
new THREE.MeshStandardMaterial({
color: new THREE.Color(planet.section.color),
emissive: new THREE.Color(planet.section.color),
emissiveIntensity: 0.3
})
);
stem.position.y = 0.3 + stemHeight / 2;
group.add(stem);
group.position.x = planet.modelX;
scene.add(group);
}
for (const planet of PLANETS) {
const group = new THREE.Group();
const centerY = planet.displayRadius + 1.65;
group.position.set(planet.modelX, centerY, 0);
const voxelMesh = createVoxelSphere(planet);
group.add(voxelMesh);
spinningMeshes.push({ mesh: voxelMesh, speed: planet.spin });
if (planet.id === "saturn") {
const ring = createSaturnRing(planet);
group.add(ring);
spinningMeshes.push({ mesh: ring, speed: -0.065 });
}
const hitRadius =
planet.id === "saturn"
? planet.displayRadius * 2.25
: planet.displayRadius * 1.08;
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const hitTarget = new THREE.Mesh(
new THREE.SphereGeometry(hitRadius, 12, 8),
hitMaterial
);
hitTarget.userData.planetId = planet.id;
group.add(hitTarget);
pickMeshes.push(hitTarget);
const distanceLabel =
planet.id === "sun"
? "Orbital origin · reference star"
: `${planet.au.toFixed(planet.au < 10 ? 3 : 2)} AU true · ${planet.modelX.toFixed(1)} m model`;
const label = makeLabel(
planet.name,
distanceLabel,
planet.id === "sun" ? "#ffd479" : planet.section.color,
planet.id === "sun" ? 14 : 12
);
label.position.y = planet.displayRadius + 3.45;
group.add(label);
scene.add(group);
planetGroups.set(planet.id, group);
createPedestal(planet);
}
const sunGlow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeGlowTexture(),
transparent: true,
opacity: 0.62,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
sunGlow.position.set(0, 8, 0);
sunGlow.scale.set(30, 30, 1);
scene.add(sunGlow);
// -------------------------------------------------------------------------
// Asteroid and Kuiper-style voxel belts
// -------------------------------------------------------------------------
function createVoxelBelt(count, auMin, auMax, yMin, yMax, spreadZ, size, color) {
const material = new THREE.MeshStandardMaterial({
color,
roughness: 1,
flatShading: true
});
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
count
);
const dummy = new THREE.Object3D();
for (let i = 0; i < count; i++) {
const au = auMin + Math.random() * (auMax - auMin);
const x = modelPosition(au);
dummy.position.set(
x,
yMin + Math.random() * (yMax - yMin),
(Math.random() - 0.5) * spreadZ
);
const s = size * (0.45 + Math.random() * 1.1);
dummy.scale.set(s, s * (0.55 + Math.random() * 0.7), s);
dummy.rotation.set(
Math.random() * Math.PI,
Math.random() * Math.PI,
Math.random() * Math.PI
);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
mesh.computeBoundingSphere();
scene.add(mesh);
}
createVoxelBelt(430, 2.1, 3.3, 0.35, 8.5, 17, 0.15, 0x74695d);
createVoxelBelt(480, 30, 55, 0.3, 11, 22, 0.18, 0x66829a);
// -------------------------------------------------------------------------
// Interface construction
// -------------------------------------------------------------------------
const targetList = document.querySelector("#targetList");
const legendSections = document.querySelector("#legendSections");
const inspector = document.querySelector("#inspector");
const inspectorContent = document.querySelector("#inspectorContent");
const toast = document.querySelector("#toast");
const modelPositionLabel = document.querySelector("#modelPosition");
const truePositionLabel = document.querySelector("#truePosition");
const currentSectionLabel = document.querySelector("#currentSection");
const sectionDot = document.querySelector("#sectionDot");
for (const planet of PLANETS) {
const button = document.createElement("button");
button.className = "target-button";
button.dataset.planetId = planet.id;
button.style.setProperty("--planet-color", planet.color);
button.innerHTML = `
<span class="planet-dot"></span>
<span>${planet.name}</span>
<small>${planet.id === "sun" ? "origin" : `${planet.au.toFixed(planet.au < 10 ? 3 : 2)} AU`}</small>
`;
button.addEventListener("click", () => selectPlanet(planet.id));
targetList.appendChild(button);
}
for (const section of SECTIONS) {
const button = document.createElement("button");
button.className = "legend-section";
button.style.setProperty("--section-color", section.color);
button.innerHTML = `
<strong>${section.shortLabel} · ${section.ratio}×</strong>
<span>${section.startAU}–${section.endAU} AU<br>${section.scale} m / AU</span>
`;
button.addEventListener("click", () => visitSection(section));
legendSections.appendChild(button);
}
let selectedPlanetId = null;
let toastTimer = 0;
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 2200);
}
function formatNumber(value, decimals = 0) {
return value.toLocaleString("en-US", {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals
});
}
function selectPlanet(id) {
const planet = planetById.get(id);
if (!planet) return;
selectedPlanetId = id;
inspector.classList.remove("hidden");
document.querySelectorAll(".target-button").forEach((button) => {
button.classList.toggle("active", button.dataset.planetId === id);
});
const section = planet.section;
const trueKm = planet.au * AU_KM;
const baselinePosition = planet.au * INNER_SCALE;
const savedDistance = Math.max(0, baselinePosition - planet.modelX);
const bodyEnlargement =
(planet.radiusKm * 1000) / planet.displayRadius;
inspectorContent.innerHTML = `
<div class="object-heading" style="--planet-color:${planet.color}">
<div class="object-orb"></div>
<div>
<h2>${planet.name}</h2>
<p>${planet.kind}</p>
</div>
</div>
<div class="stat-grid">
<div class="stat">
<label>True orbital distance</label>
<strong>${planet.id === "sun" ? "Origin" : `${planet.au.toFixed(planet.au < 10 ? 4 : 3)} AU`}</strong>
<small>${
planet.id === "sun"
? "Reference center"
: `${formatNumber(trueKm / 1e6, 1)} million km`
}</small>
</div>
<div class="stat">
<label>Model position</label>
<strong>${planet.modelX.toFixed(1)} m</strong>
<small>${section.shortLabel} · ${section.scale} m/AU</small>
</div>
<div class="stat">
<label>Local compression</label>
<strong>${section.ratio.toFixed(section.ratio % 1 ? 2 : 0)}×</strong>
<small>Relative to the 12 m/AU inner scale</small>
</div>
<div class="stat">
<label>Space removed</label>
<strong>${savedDistance.toFixed(1)} m</strong>
<small>Vs. an uncompressed ${INNER_SCALE} m/AU corridor</small>
</div>
<div class="stat">
<label>True mean radius</label>
<strong>${formatNumber(planet.radiusKm)} km</strong>
<small>Physical body radius</small>
</div>
<div class="stat">
<label>Voxel exhibit radius</label>
<strong>${planet.displayRadius.toFixed(2)} m</strong>
<small>Enlarged ≈ ${formatNumber(bodyEnlargement / 1e6, 2)} million×</small>
</div>
</div>
<div class="comparison">
<h3>True distance vs. compressed model</h3>
<div class="bar-row">
<div class="bar-label">
<span>True AU</span>
<span>${planet.au.toFixed(planet.au < 10 ? 4 : 3)} AU</span>
</div>
<div class="bar-track">
<div class="bar-fill actual" style="width:${Math.max(
0.5,
(planet.au / MAX_TRUE_AU) * 100
)}%"></div>
</div>
</div>
<div class="bar-row">
<div class="bar-label">
<span>Model metres</span>
<span>${planet.modelX.toFixed(1)} m</span>
</div>
<div class="bar-track">
<div class="bar-fill model" style="width:${Math.max(
0.5,
(planet.modelX / MAX_MODEL_X) * 100
)}%"></div>
</div>
</div>
<p class="comparison-note">
Both bars use fixed domains: 0–${MAX_TRUE_AU} AU and 0–${MAX_MODEL_X.toFixed(
1
)} model metres. Body sizes use a separate logarithmic exhibit scale.
</p>
</div>
<div class="compression-note" style="--section-color:${section.color}">
<strong>${section.label}</strong><br>
${section.description}<br>
True range: ${section.startAU}–${section.endAU} AU ·
Model span: ${(section.modelEnd - section.modelStart).toFixed(
1
)} m · ${section.ratio.toFixed(
section.ratio % 1 ? 2 : 0
)}× local compression.
</div>
<div class="inspector-actions">
<button class="primary-button" id="focusSelected">Fly to ${planet.name}</button>
<button class="mini-button" id="focusSection">Section boundary</button>
</div>
<p class="comparison-note">${planet.note}</p>
`;
inspectorContent.scrollTop = 0;
document.querySelector("#focusSelected").addEventListener("click", () => {
flyToPlanet(planet);
});
document.querySelector("#focusSection").addEventListener("click", () => {
visitSection(section);
});
}
// -------------------------------------------------------------------------
// Direct camera controls: walking, mouse look, picking, and fly transitions
// -------------------------------------------------------------------------
const keys = new Set();
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let dragging = false;
let pointerMoved = 0;
let lastPointerX = 0;
let lastPointerY = 0;
let moveSpeed = 12;
let flyTransition = null;
const startPosition = new THREE.Vector3(-28, 9, 22);
const startTarget = new THREE.Vector3(18, 3, 0);
function flyTo(position, target, duration = 1.35) {
const endQuaternion = new THREE.Quaternion();
const temporaryCamera = camera.clone();
temporaryCamera.position.copy(position);
temporaryCamera.lookAt(target);
endQuaternion.copy(temporaryCamera.quaternion);
flyTransition = {
start: performance.now(),
duration,
fromPosition: camera.position.clone(),
toPosition: position.clone(),
fromQuaternion: camera.quaternion.clone(),
toQuaternion: endQuaternion
};
}
function flyToPlanet(planet) {
const group = planetGroups.get(planet.id);
const target = group.position.clone();
const distance = Math.max(10, planet.displayRadius * 2.8);
const position = new THREE.Vector3(
target.x - distance * 0.88,
target.y + planet.displayRadius * 0.55 + 1.2,
target.z + distance
);
flyTo(position, target);
showToast(`Flying to ${planet.name}`);
}
function visitSection(section) {
const x = section.modelStart;
const target = new THREE.Vector3(x, 3.8, 0);
const position = new THREE.Vector3(x - 19, 8.5, 19);
flyTo(position, target);
showToast(`${section.label} · ${section.ratio}× compression`);
}
function resetView() {
flyTo(startPosition.clone(), startTarget.clone());
}
function overview() {
const target = new THREE.Vector3(385, 0, 0);
const position = new THREE.Vector3(385, 230, 430);
flyTo(position, target, 1.7);
showToast("Overview · orbital sections remain deliberately compressed");
}
function updateManualCamera(delta) {
if (flyTransition) return;
const sprint = keys.has("ShiftLeft") || keys.has("ShiftRight");
const speed = moveSpeed * (sprint ? 2.45 : 1);
const forward = new THREE.Vector3(Math.sin(yaw), 0, -Math.cos(yaw));
const right = new THREE.Vector3(Math.cos(yaw), 0, Math.sin(yaw));
const movement = new THREE.Vector3();
if (keys.has("KeyW") || keys.has("ArrowUp")) movement.add(forward);
if (keys.has("KeyS") || keys.has("ArrowDown")) movement.sub(forward);
if (keys.has("KeyD") || keys.has("ArrowRight")) movement.add(right);
if (keys.has("KeyA") || keys.has("ArrowLeft")) movement.sub(right);
if (movement.lengthSq() > 0) {
movement.normalize().multiplyScalar(speed * delta);
camera.position.add(movement);
}
if (keys.has("Space")) camera.position.y += speed * delta;
if (keys.has("KeyC") || keys.has("ControlLeft")) {
camera.position.y -= speed * delta;
}
camera.position.y = Math.max(1.35, camera.position.y);
camera.rotation.set(pitch, yaw, 0, "YXZ");
}
function pickPlanet(event) {
const bounds = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y = -((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
if (hits.length) {
selectPlanet(hits[0].object.userData.planetId);
return true;
}
return false;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
dragging = false;
pointerMoved = 0;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
pointerMoved += Math.abs(deltaX) + Math.abs(deltaY);
if (pointerMoved > 4) dragging = true;
if (dragging) {
yaw -= deltaX * 0.0032;
pitch -= deltaY * 0.0028;
pitch = THREE.MathUtils.clamp(pitch, -1.35, 1.35);
camera.rotation.set(pitch, yaw, 0, "YXZ");
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
renderer.domElement.classList.remove("dragging");
if (!dragging && pointerMoved < 7) {
pickPlanet(event);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
dragging = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("dblclick", (event) => {
if (pickPlanet(event)) {
const planet = planetById.get(selectedPlanetId);
flyToPlanet(planet);
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
moveSpeed = THREE.MathUtils.clamp(
moveSpeed + Math.sign(event.deltaY) * -1.5,
4,
34
);
showToast(`Walk speed: ${Math.round(moveSpeed)} m/s`);
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("keydown", (event) => {
if (
[
"Space",
"ArrowUp",
"ArrowDown",
"ArrowLeft",
"ArrowRight"
].includes(event.code)
) {
event.preventDefault();
}
keys.add(event.code);
if (event.code === "KeyF" && selectedPlanetId) {
flyToPlanet(planetById.get(selectedPlanetId));
}
if (event.code === "KeyO") {
overview();
}
if (event.code === "KeyR") {
resetView();
}
if (event.code === "Escape") {
inspector.classList.add("hidden");
}
});
window.addEventListener("keyup", (event) => {
keys.delete(event.code);
});
window.addEventListener("blur", () => {
keys.clear();
});
document.querySelectorAll(".touch-controls button").forEach((button) => {
button.addEventListener("pointerdown", (event) => {
event.preventDefault();
button.setPointerCapture(event.pointerId);
keys.add(button.dataset.key);
});
const release = () => keys.delete(button.dataset.key);
button.addEventListener("pointerup", release);
button.addEventListener("pointercancel", release);
});
document.querySelector("#closeInspector").addEventListener("click", () => {
inspector.classList.add("hidden");
});
document.querySelector("#overviewButton").addEventListener("click", overview);
document.querySelector("#resetButton").addEventListener("click", resetView);
// -------------------------------------------------------------------------
// Animation and live readouts
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
if (flyTransition) {
const raw = THREE.MathUtils.clamp(
(now - flyTransition.start) / flyTransition.duration,
0,
1
);
const eased = 1 - Math.pow(1 - raw, 3);
camera.position.lerpVectors(
flyTransition.fromPosition,
flyTransition.toPosition,
eased
);
camera.quaternion.slerpQuaternions(
flyTransition.fromQuaternion,
flyTransition.toQuaternion,
eased
);
if (raw >= 1) {
const euler = new THREE.Euler().setFromQuaternion(
flyTransition.toQuaternion,
"YXZ"
);
yaw = euler.y;
pitch = euler.x;
flyTransition = null;
}
} else {
updateManualCamera(delta);
}
for (const entry of spinningMeshes) {
entry.mesh.rotation.y += entry.speed * delta;
}
stars.rotation.y += delta * 0.0007;
sunGlow.material.opacity = 0.57 + Math.sin(now * 0.0013) * 0.055;
const modelX = Math.max(0, camera.position.x);
const au = truePosition(modelX);
const section = sectionForModel(modelX);
modelPositionLabel.textContent = `${modelX.toFixed(1)} m`;
truePositionLabel.textContent = `≈ ${au.toFixed(au < 10 ? 2 : 1)} AU from Sun`;
currentSectionLabel.textContent = section.label;
currentSectionLabel.parentElement.style.color = section.color;
sectionDot.style.background = section.color;
sectionDot.style.color = section.color;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
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));
});
// Open on Earth so the inspector immediately demonstrates the comparison.
selectPlanet("earth");
</script>
</body>
</html>
```