Prompt specification
Build or customize the Three.js 3D scene "Linear and Logarithmic Distance Explorer" 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: Linear and Logarithmic Distance Explorer
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/linear-and-logarithmic-distance-explorer-x3764
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing astronomical size and distance scales. Compare the same astronomical distances on linear and logarithmic axes. Show how position changes with the mapping and never interpret compressed spacing as physical closeness. Voxel style.
Verify the behavior against the actual geometry and data in each relevant state. Use schematic labels for deliberately synthetic elements.
Technical checks: Show zero on the linear scale and place it outside the logarithmic scale. Keep the Sun marker separate from Earth at 1 AU and synchronize selection across the views.
Return one complete HTML document. The file must run in a sandbox allowing inline scripts and the cdnjs Three.js r160 module. Construct procedural assets, use local event handlers and avoid remote assets, runtime network requests besides Three.js, pointer lock and native form submission. Keep the main requested geometry visible in the initial view.
Working Three.js Starter (linear-and-logarithmic-distance-explorer-x3764):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Astronomical Distance Atlas</title>
<style>
:root {
color-scheme: dark;
--bg: #050a12;
--panel: #081321;
--panel-2: #0d1728;
--line: #263b53;
--text: #e7f0fa;
--muted: #91a4bb;
--cyan: #58d6ff;
--amber: #ffd166;
--danger: #ff7a6e;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
button { font: inherit; }
#app {
width: 100%;
height: 100%;
display: grid;
grid-template-rows: auto minmax(280px, 1fr) 172px;
background: var(--bg);
}
header {
position: relative;
z-index: 5;
min-height: 94px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 12px 18px;
border-bottom: 1px solid var(--line);
background: #070d18;
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}
.title-block { min-width: 0; }
h1 {
margin: 0 0 5px;
color: var(--text);
font-size: clamp(16px, 1.6vw, 23px);
letter-spacing: 0.08em;
line-height: 1.1;
}
.subtitle {
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.header-right {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 10px;
flex-wrap: wrap;
}
.warning {
max-width: 600px;
padding: 9px 11px;
border: 1px solid #75433f;
border-left: 4px solid var(--danger);
background: #251519;
color: #ffd7d2;
font-size: 10px;
line-height: 1.45;
}
.warning strong { color: #fff0ed; }
#resetView {
cursor: pointer;
padding: 9px 11px;
color: var(--text);
border: 1px solid #3b5875;
border-radius: 0;
background: #102238;
font-size: 10px;
letter-spacing: 0.06em;
}
#resetView:hover,
#resetView:focus-visible {
border-color: var(--cyan);
background: #143049;
outline: none;
}
#stage {
position: relative;
min-height: 0;
overflow: hidden;
background: #050a12;
}
#glCanvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#glCanvas:active { cursor: grabbing; }
.panel-overlay {
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 100%;
padding: 13px 15px;
pointer-events: none;
z-index: 2;
}
#linearPanel { left: 0; }
#logPanel { left: 50%; }
.panel-card {
width: min(390px, calc(100% - 4px));
padding: 10px 11px;
border: 1px solid rgba(72, 101, 132, 0.72);
background: rgba(5, 12, 23, 0.84);
box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.18);
backdrop-filter: blur(3px);
}
.panel-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
color: var(--cyan);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.1em;
}
.domain {
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.selection-line {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
margin-top: 8px;
}
#selectedName {
overflow: hidden;
color: var(--text);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.05em;
text-overflow: ellipsis;
white-space: nowrap;
}
.distance {
flex: 0 0 auto;
color: var(--amber);
font-size: 11px;
}
.position-line {
display: grid;
grid-template-columns: 68px 1fr;
gap: 8px;
align-items: center;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
}
.position-value {
color: var(--text);
font-size: 10px;
text-align: right;
}
.position-track {
position: relative;
height: 8px;
border: 1px solid #324c67;
background:
repeating-linear-gradient(90deg, transparent 0 19%, rgba(79, 118, 151, 0.18) 19% 20%),
#0a1422;
}
.position-pin {
position: absolute;
top: -3px;
width: 3px;
height: 12px;
transform: translateX(-50%);
background: var(--amber);
box-shadow: 0 0 8px rgba(255, 209, 102, 0.65);
}
.position-pin.hidden { display: none; }
.panel-note {
min-height: 26px;
margin-top: 7px;
color: #a8b9cb;
font-size: 8px;
line-height: 1.4;
}
#stageHint {
position: absolute;
z-index: 3;
left: 50%;
bottom: 10px;
transform: translateX(-50%);
padding: 6px 9px;
border: 1px solid rgba(69, 95, 122, 0.7);
background: rgba(4, 10, 18, 0.84);
color: #9eb0c4;
font-size: 9px;
pointer-events: none;
white-space: nowrap;
}
footer {
position: relative;
z-index: 5;
min-width: 0;
border-top: 1px solid var(--line);
background: #070d17;
box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.25);
}
.ledger-head {
height: 31px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 0 13px;
border-bottom: 1px solid #1d3046;
color: var(--muted);
font-size: 9px;
}
.ledger-head strong {
color: var(--text);
letter-spacing: 0.07em;
}
#ledger {
height: 140px;
display: flex;
align-items: stretch;
gap: 7px;
padding: 9px 11px 10px;
overflow-x: auto;
overflow-y: hidden;
scrollbar-color: #38516d #0a121e;
scrollbar-width: thin;
}
.ledger-card {
position: relative;
flex: 0 0 142px;
height: 116px;
padding: 8px 8px 7px 11px;
border: 1px solid #263d55;
border-radius: 0;
color: var(--text);
background: #0b1422;
text-align: left;
cursor: pointer;
}
.ledger-card::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 4px;
background: var(--object-color);
}
.ledger-card:hover,
.ledger-card:focus-visible {
border-color: #6d8aa7;
background: #101d2f;
outline: none;
}
.ledger-card[aria-pressed="true"] {
border-color: var(--amber);
background: #172235;
box-shadow: inset 0 0 0 1px rgba(255, 209, 102, 0.18);
}
.card-name {
display: block;
min-height: 26px;
color: var(--text);
font-size: 10px;
font-weight: 800;
line-height: 1.25;
}
.card-distance {
display: block;
margin: 2px 0 7px;
color: var(--object-color);
font-size: 9px;
}
.card-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 5px;
}
.card-grid span {
display: block;
color: #72879f;
font-size: 7px;
letter-spacing: 0.04em;
}
.card-grid b {
display: block;
margin-top: 2px;
color: #d6e3ef;
font-size: 8px;
font-weight: 500;
white-space: nowrap;
}
@media (max-width: 820px) {
header {
min-height: 116px;
align-items: flex-start;
}
.header-right {
max-width: 45%;
}
.warning {
font-size: 8px;
}
#app {
grid-template-rows: auto minmax(300px, 1fr) 164px;
}
.panel-overlay {
width: 100%;
height: 50%;
}
#linearPanel { top: 0; left: 0; }
#logPanel { top: 50%; left: 0; }
.panel-card {
width: min(360px, calc(100% - 4px));
padding: 7px 8px;
}
.panel-title { font-size: 10px; }
.domain { font-size: 7px; }
.position-line { margin-top: 4px; }
.panel-note { display: none; }
#stageHint { bottom: 5px; font-size: 7px; }
}
</style>
</head>
<body>
<main id="app">
<header>
<div class="title-block">
<h1>VOXEL ASTRONOMICAL DISTANCE ATLAS</h1>
<div class="subtitle">
One distance set, two display mappings. Distances are heliocentric AU values.
Voxel silhouettes and vertical lanes are schematic, not physical scale.
</div>
</div>
<div class="header-right">
<div class="warning">
<strong>DISPLAY TRANSFORM ONLY.</strong>
Logarithmic spacing does not mean objects are physically closer.
Only the labeled AU distance is physical; screen spacing is the chosen mapping.
</div>
<button id="resetView" type="button">RESET CAMERA</button>
</div>
</header>
<section id="stage" aria-label="Interactive linear and logarithmic distance comparison">
<canvas id="glCanvas"></canvas>
<div class="panel-overlay" id="linearPanel">
<div class="panel-card">
<div class="panel-title">
<span>LINEAR / TRUE FRACTION</span>
<span class="domain">0–268,332 AU</span>
</div>
<div class="domain">
x = distance ÷ 268,332 AU
</div>
<div class="selection-line">
<span id="linearName" aria-live="polite">NEPTUNE</span>
<span class="distance" id="linearDistance">30.07 AU</span>
</div>
<div class="position-line">
<span>LINEAR X</span>
<span class="position-value" id="linearPosition">0.01121%</span>
</div>
<div class="position-track">
<i class="position-pin" id="linearPin"></i>
</div>
<div class="panel-note">
The linear scale exposes the actual crowding: nearby Solar System objects collapse
into a tiny fraction of the full distance.
</div>
</div>
</div>
<div class="panel-overlay" id="logPanel">
<div class="panel-card">
<div class="panel-title">
<span>LOGARITHMIC / RATIO</span>
<span class="domain">1–268,332 AU</span>
</div>
<div class="domain">
x = ln(distance ÷ 1 AU) ÷ ln(268,332 AU)
</div>
<div class="selection-line">
<span id="logName" aria-live="polite">NEPTUNE</span>
<span class="distance" id="logDistance">30.07 AU</span>
</div>
<div class="position-line">
<span>LOG X</span>
<span class="position-value" id="logPosition">27.23%</span>
</div>
<div class="position-track">
<i class="position-pin" id="logPin"></i>
</div>
<div class="panel-note">
The log domain starts at 1 AU. Values below 1 AU receive no coordinate and are
shown in a separately labeled off-scale exhibit, never clamped to the origin.
</div>
</div>
</div>
<div id="stageHint">DRAG: TILT · WHEEL: ZOOM · CLICK OBJECT OR CARD: SELECT</div>
</section>
<footer>
<div class="ledger-head">
<strong>OBJECT LEDGER — SELECT TO SYNCHRONIZE BOTH VIEWS</strong>
<span>LINEAR X = DATA COORDINATE · LOG X = DATA COORDINATE · COMPRESSED SPACING ≠ PHYSICAL CLOSENESS</span>
</div>
<div id="ledger" aria-label="Astronomical distance data"></div>
</footer>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const DOMAIN_MAX = 268332;
const LINEAR_MIN = 0;
const LOG_MIN = 1;
const AXIS_MIN = -6;
const AXIS_MAX = 6;
const AXIS_LENGTH = AXIS_MAX - AXIS_MIN;
const objects = [
{ id: "sun", name: "Sun", distance: 0, displayDistance: "0 AU", color: "#ffb62e", type: "star", visualRadius: 0.38 },
{ id: "mercury", name: "Mercury", distance: 0.3871, displayDistance: "0.3871 AU", color: "#a6a6a6", type: "rock", visualRadius: 0.25 },
{ id: "venus", name: "Venus", distance: 0.7233, displayDistance: "0.7233 AU", color: "#e6b86d", type: "rock", visualRadius: 0.29 },
{ id: "earth", name: "Earth", distance: 1, displayDistance: "1 AU", color: "#4db8ff", type: "earth", visualRadius: 0.28 },
{ id: "mars", name: "Mars", distance: 1.5237, displayDistance: "1.5237 AU", color: "#e56b4b", type: "rock", visualRadius: 0.26 },
{ id: "jupiter", name: "Jupiter", distance: 5.2044, displayDistance: "5.2044 AU", color: "#d6a878", type: "giant", visualRadius: 0.40 },
{ id: "saturn", name: "Saturn", distance: 9.5826, displayDistance: "9.5826 AU", color: "#ead79a", type: "ringed", visualRadius: 0.36 },
{ id: "uranus", name: "Uranus", distance: 19.2184, displayDistance: "19.2184 AU", color: "#75e3e6", type: "giant", visualRadius: 0.36 },
{ id: "neptune", name: "Neptune", distance: 30.07, displayDistance: "30.07 AU", color: "#5b7cff", type: "giant", visualRadius: 0.37 },
{ id: "voyager", name: "Voyager 1", distance: 167, displayDistance: "≈167 AU", color: "#f0f4ff", type: "craft", visualRadius: 0.20 },
{ id: "oort", name: "Oort Cloud", distance: 100000, displayDistance: "≈100,000 AU", color: "#b68cff", type: "cloud", visualRadius: 0.44 },
{ id: "proxima", name: "Proxima Centauri", distance: 268332, displayDistance: "268,332 AU", color: "#ff776f", type: "star", visualRadius: 0.37 }
];
const objectById = new Map(objects.map(o => [o.id, o]));
const lanes = {
linear: {
sun: 1.1, mercury: 2.4, venus: 3.7, earth: 1.9, mars: 3.0,
jupiter: 4.2, saturn: 2.6, uranus: 3.8, neptune: 1.4,
voyager: 2.9, oort: 4.1, proxima: 1.8
},
log: {
earth: 1.4, mars: 2.8, jupiter: 4.1, saturn: 2.2, uranus: 3.5,
neptune: 1.4, voyager: 2.9, oort: 4.1, proxima: 1.7
}
};
function clamp01(v) {
return Math.max(0, Math.min(1, v));
}
// True data coordinates. These functions drive the actual Three.js geometry.
function linearFraction(distance) {
return clamp01((distance - LINEAR_MIN) / (DOMAIN_MAX - LINEAR_MIN));
}
function logFraction(distance) {
// Important: a value below the log-domain minimum has NO coordinate.
// Returning null prevents 0 AU from being clamped onto Earth at 1 AU.
if (distance < LOG_MIN) return null;
return clamp01(Math.log(distance / LOG_MIN) / Math.log(DOMAIN_MAX / LOG_MIN));
}
function linearX(distance) {
return AXIS_MIN + AXIS_LENGTH * linearFraction(distance);
}
function logX(distance) {
const fraction = logFraction(distance);
return fraction === null ? null : AXIS_MIN + AXIS_LENGTH * fraction;
}
function formatNumber(value, maximumFractionDigits = 6) {
return value.toLocaleString("en-US", {
minimumFractionDigits: 0,
maximumFractionDigits
});
}
function formatPercent(value) {
if (value === null) return "OFF-DOMAIN";
if (value === 0) return "0.00000%";
if (value < 0.001) return value.toFixed(5) + "%";
if (value < 1) return value.toFixed(4) + "%";
if (value < 10) return value.toFixed(3) + "%";
return value.toFixed(2) + "%";
}
const stage = document.getElementById("stage");
const canvas = document.getElementById("glCanvas");
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.setClearColor(0x050a12, 1);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let selectedId = "neptune";
let cameraPitch = 0.53;
let cameraZoom = 1;
let stageWidth = 1;
let stageHeight = 1;
let dragging = false;
let dragMoved = false;
let dragStartY = 0;
let dragStartPitch = 0;
function makeMaterial(color, options = {}) {
return new THREE.MeshLambertMaterial({ color, ...options });
}
function makeLabelSprite(text, accent = "#9eb6ce", boxed = true) {
const measureCanvas = document.createElement("canvas");
const measure = measureCanvas.getContext("2d");
const font = "700 21px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
measure.font = font;
const textWidth = Math.ceil(measure.measureText(text).width);
const width = Math.max(32, textWidth + (boxed ? 22 : 6));
const height = boxed ? 38 : 30;
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
ctx.imageSmoothingEnabled = false;
ctx.clearRect(0, 0, width, height);
if (boxed) {
ctx.fillStyle = "rgba(4, 10, 18, 0.88)";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 3, height);
ctx.strokeStyle = "rgba(87, 113, 141, 0.85)";
ctx.lineWidth = 2;
ctx.strokeRect(1, 1, width - 2, height - 2);
}
ctx.font = font;
ctx.textBaseline = "middle";
ctx.textAlign = "left";
ctx.fillStyle = boxed ? "#e6eef7" : accent;
ctx.fillText(text, boxed ? 10 : 3, height / 2 + 1);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const worldWidth = width / 105;
sprite.scale.set(worldWidth, boxed ? 0.34 : 0.23, 1);
sprite.renderOrder = 30;
sprite.userData.labelWidth = worldWidth;
return sprite;
}
function addBox(scene, width, height, depth, x, y, z, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
makeMaterial(color, options)
);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
function colorForVoxel(obj, i, j, k) {
const base = new THREE.Color(obj.color);
if (obj.id === "earth") {
const land = ((i * 7 + j * 13 + k * 11) % 11 < 3);
return land ? new THREE.Color("#67d36b") : base;
}
if (obj.id === "jupiter") {
if (Math.abs(j) <= 1 && (i + k) % 3 !== 0) return new THREE.Color("#a86e4e");
if (j === 2) return new THREE.Color("#f1d6ad");
}
if (obj.id === "saturn" && Math.abs(j) === 1) return new THREE.Color("#bca66f");
if (obj.id === "sun") {
return (i + 2 * j - k) % 5 === 0 ? new THREE.Color("#ffe083") : base;
}
if (obj.id === "proxima" && (i + j + k) % 4 === 0) return new THREE.Color("#ffb0a8");
const variation = ((i + 3 * j + 5 * k) % 7 - 3) * 0.035;
return base.offsetHSL(0, 0, variation);
}
function createVoxelModel(obj) {
const root = new THREE.Group();
if (obj.type === "craft") {
const body = addBox(root, 0.13, 0.17, 0.13, 0, 0, 0, "#dce8f5");
const gold = addBox(root, 0.16, 0.09, 0.09, 0.11, 0, 0, "#d6ad55");
const dish = addBox(root, 0.20, 0.035, 0.20, -0.09, 0.12, 0, "#b8c8d8");
const antenna = addBox(root, 0.025, 0.20, 0.025, -0.15, 0.20, 0, "#f4f7fb");
body.userData.objectId = obj.id;
gold.userData.objectId = obj.id;
dish.userData.objectId = obj.id;
antenna.userData.objectId = obj.id;
return { root, meshes: [body, gold, dish, antenna] };
}
if (obj.type === "cloud") {
const count = 72;
const cell = 0.075;
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(cell * 0.88, cell * 0.88, cell * 0.88),
makeMaterial(0xffffff, { transparent: true, opacity: 0.9 }),
count
);
const dummy = new THREE.Object3D();
let seed = 1234567;
const random = () => {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
};
for (let n = 0; n < count; n++) {
const theta = random() * Math.PI * 2;
const phi = Math.acos(2 * random() - 1);
const radius = 0.31 + random() * 0.20;
dummy.position.set(
radius * Math.sin(phi) * Math.cos(theta),
radius * Math.cos(phi),
radius * Math.sin(phi) * Math.sin(theta)
);
dummy.rotation.set(random() * 0.5, random() * Math.PI, random() * 0.5);
dummy.updateMatrix();
mesh.setMatrixAt(n, dummy.matrix);
mesh.setColorAt(n, colorForVoxel(obj, n % 5, n % 3, n % 7));
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.userData.objectId = obj.id;
root.add(mesh);
return { root, meshes: [mesh] };
}
const radius = obj.type === "giant" || obj.type === "star" ? 3 : 2;
const cell = obj.type === "star" ? 0.125 : obj.type === "giant" ? 0.13 : 0.12;
const coords = [];
for (let i = -radius; i <= radius; i++) {
for (let j = -radius; j <= radius; j++) {
for (let k = -radius; k <= radius; k++) {
if (i * i + j * j + k * k <= radius * radius + 0.45) {
coords.push([i, j, k]);
}
}
}
}
const mesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(cell * 0.9, cell * 0.9, cell * 0.9),
makeMaterial(0xffffff, {
emissive: obj.type === "star" ? 0x3b1800 : 0x000000,
emissiveIntensity: obj.type === "star" ? 0.65 : 0
}),
coords.length
);
const dummy = new THREE.Object3D();
coords.forEach(([i, j, k], index) => {
dummy.position.set(i * cell, j * cell, k * cell);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
mesh.setColorAt(index, colorForVoxel(obj, i, j, k));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
mesh.userData.objectId = obj.id;
root.add(mesh);
const meshes = [mesh];
if (obj.type === "ringed") {
const ringCount = 28;
const ringMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.085, 0.045, 0.085),
makeMaterial("#d8c58a"),
ringCount
);
for (let n = 0; n < ringCount; n++) {
const angle = n / ringCount * Math.PI * 2;
dummy.position.set(Math.cos(angle) * 0.50, -0.035, Math.sin(angle) * 0.50);
dummy.rotation.set(0, -angle, 0);
dummy.updateMatrix();
ringMesh.setMatrixAt(n, dummy.matrix);
}
ringMesh.instanceMatrix.needsUpdate = true;
ringMesh.userData.objectId = obj.id;
root.add(ringMesh);
meshes.push(ringMesh);
}
return { root, meshes };
}
function createSelectionFrame(radius) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.95,
depthTest: false
});
const size = radius * 2.15;
const t = 0.025;
const half = size / 2;
const parts = [
[size, t, t, 0, half, half],
[size, t, t, 0, -half, half],
[size, t, t, 0, half, -half],
[size, t, t, 0, -half, -half],
[t, size, t, half, 0, half],
[t, size, t, -half, 0, half],
[t, size, t, half, 0, -half],
[t, size, t, -half, 0, -half],
[t, t, size, half, half, 0],
[t, t, size, -half, half, 0],
[t, t, size, half, -half, 0],
[t, t, size, -half, -half, 0]
];
for (const [w, h, d, x, y, z] of parts) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.renderOrder = 40;
group.add(mesh);
}
return group;
}
function createAxis(scene, logarithmic) {
const axisGroup = new THREE.Group();
scene.add(axisGroup);
addBox(axisGroup, AXIS_LENGTH + 0.25, 0.10, 0.28, 0, 0, 0, "#36516b");
addBox(axisGroup, AXIS_LENGTH + 0.25, 0.035, 0.42, 0, -0.075, 0, "#182d43");
const tickValues = logarithmic
? [1, 10, 100, 1000, 10000, 100000, DOMAIN_MAX]
: [0, 50000, 100000, 150000, 200000, 250000, DOMAIN_MAX];
for (const value of tickValues) {
const x = logarithmic ? logX(value) : linearX(value);
if (x === null) continue;
addBox(axisGroup, 0.035, 0.42, 0.34, x, 0.04, 0, "#54718d");
let text;
if (value === 0) text = "0";
else if (value >= DOMAIN_MAX) text = "268,332";
else if (value >= 100000) text = Math.round(value / 1000) + "k";
else text = formatNumber(value);
const label = makeLabelSprite(text, "#829bb4", false);
label.position.set(x, -0.62, 0);
axisGroup.add(label);
}
const unit = makeLabelSprite(logarithmic ? "LOG AU" : "LINEAR AU", "#6f8ba6", false);
unit.position.set(0, -1.00, 0);
unit.scale.multiplyScalar(1.18);
axisGroup.add(unit);
if (logarithmic) {
const inset = new THREE.Group();
scene.add(inset);
const borderColor = "#5a496f";
addBox(inset, 5.3, 0.035, 0.035, -2.7, -0.88, -0.15, borderColor);
addBox(inset, 5.3, 0.035, 0.035, -2.7, -3.78, -0.15, borderColor);
addBox(inset, 0.035, 2.9, 0.035, -5.35, -2.33, -0.15, borderColor);
addBox(inset, 0.035, 2.9, 0.035, -0.05, -2.33, -0.15, borderColor);
const note = makeLabelSprite("OFF-SCALE ITEMS · NO LOG X", "#c79bff");
note.position.set(-2.7, -0.60, -0.12);
note.scale.multiplyScalar(0.92);
inset.add(note);
}
}
function createView(key, logarithmic) {
const scene = new THREE.Scene();
scene.background = new THREE.Color(logarithmic ? 0x0b1120 : 0x07131e);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
scene.add(new THREE.AmbientLight(0xa9c8e6, 1.15));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.2);
keyLight.position.set(-5, 10, 8);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4aa8ff, 0.9);
rimLight.position.set(7, 3, -6);
scene.add(rimLight);
createAxis(scene, logarithmic);
const view = {
key,
logarithmic,
scene,
camera,
entries: new Map(),
pickables: [],
selectionFrame: null,
x: 0, y: 0, width: 1, height: 1
};
for (const obj of objects) {
const fraction = logarithmic ? logFraction(obj.distance) : linearFraction(obj.distance);
const isOffDomain = logarithmic && fraction === null;
let x;
let y;
if (isOffDomain) {
// These x positions belong to a separated exhibit, not to the log ruler.
const offScaleY = { sun: -1.42, mercury: -2.40, venus: -3.38 };
x = -4.45;
y = offScaleY[obj.id];
} else {
x = logarithmic ? logX(obj.distance) : linearX(obj.distance);
y = lanes[logarithmic ? "log" : "linear"][obj.id];
}
const entry = new THREE.Group();
entry.position.set(x, y, 0);
scene.add(entry);
const model = createVoxelModel(obj);
entry.add(model.root);
for (const mesh of model.meshes) {
mesh.userData.objectId = obj.id;
view.pickables.push(mesh);
}
const distanceText = obj.displayDistance;
const labelText = logarithmic && isOffDomain
? `${obj.name.toUpperCase()} · ${distanceText} · OFF-DOMAIN`
: `${obj.name.toUpperCase()} · ${distanceText}`;
const label = makeLabelSprite(labelText, obj.color);
const side = x > 5 ? -1 : 1;
label.position.set(side * (label.userData.labelWidth / 2 + 0.10), obj.visualRadius + 0.18, 0);
label.userData.objectId = obj.id;
entry.add(label);
view.pickables.push(label);
let stem = null;
let axisMarker = null;
if (!isOffDomain) {
const stemHeight = Math.max(0.08, y - 0.08);
stem = addBox(
scene,
0.025,
stemHeight,
0.025,
x,
stemHeight / 2,
-0.06,
"#29465f"
);
stem.userData.objectId = obj.id;
view.pickables.push(stem);
axisMarker = addBox(
scene,
0.16,
0.10,
0.38,
x,
0.12,
0,
"#3d617e"
);
axisMarker.userData.objectId = obj.id;
view.pickables.push(axisMarker);
}
view.entries.set(obj.id, {
obj,
group: entry,
x,
y,
stem,
axisMarker,
offDomain: isOffDomain
});
}
return view;
}
const linearView = createView("linear", false);
const logView = createView("log", true);
const views = [linearView, logView];
function updateCamera(view) {
const aspect = Math.max(0.25, view.width / view.height);
const worldWidth = 15.8 / cameraZoom;
const worldHeight = worldWidth / aspect;
view.camera.left = -worldWidth / 2;
view.camera.right = worldWidth / 2;
view.camera.top = worldHeight / 2;
view.camera.bottom = -worldHeight / 2;
view.camera.updateProjectionMatrix();
const targetY = 1.0;
const radius = 20;
view.camera.position.set(
0,
targetY + Math.sin(cameraPitch) * radius,
Math.cos(cameraPitch) * radius
);
view.camera.lookAt(0, targetY, 0);
view.camera.updateMatrixWorld();
}
function layoutViews() {
stageWidth = Math.max(1, stage.clientWidth);
stageHeight = Math.max(1, stage.clientHeight);
renderer.setSize(stageWidth, stageHeight, false);
if (stageWidth >= 820) {
const half = stageWidth / 2;
Object.assign(linearView, { x: 0, y: 0, width: half, height: stageHeight });
Object.assign(logView, { x: half, y: 0, width: stageWidth - half, height: stageHeight });
} else {
const half = stageHeight / 2;
Object.assign(linearView, { x: 0, y: 0, width: stageWidth, height: half });
Object.assign(logView, { x: 0, y: half, width: stageWidth, height: stageHeight - half });
}
views.forEach(updateCamera);
}
const resizeObserver = new ResizeObserver(layoutViews);
resizeObserver.observe(stage);
layoutViews();
const ledger = document.getElementById("ledger");
const cardById = new Map();
for (const obj of objects) {
const card = document.createElement("button");
card.type = "button";
card.className = "ledger-card";
card.style.setProperty("--object-color", obj.color);
card.setAttribute("aria-pressed", "false");
const lp = linearFraction(obj.distance) * 100;
const lg = logFraction(obj.distance);
const logText = lg === null ? "OFF-DOMAIN" : formatPercent(lg * 100);
card.innerHTML = `
<span class="card-name">${obj.name}</span>
<span class="card-distance">${obj.displayDistance}</span>
<span class="card-grid">
<span>LINEAR X<b>${formatPercent(lp)}</b></span>
<span>LOG X<b>${logText}</b></span>
</span>
`;
card.addEventListener("click", () => selectObject(obj.id, true));
ledger.appendChild(card);
cardById.set(obj.id, card);
}
function updateSelectionFrames() {
for (const view of views) {
if (view.selectionFrame) {
view.scene.remove(view.selectionFrame);
view.selectionFrame.traverse(child => {
if (child.geometry) child.geometry.dispose();
});
view.selectionFrame = null;
}
const entry = view.entries.get(selectedId);
const frame = createSelectionFrame(entry.obj.visualRadius);
frame.position.copy(entry.group.position);
frame.renderOrder = 45;
view.scene.add(frame);
view.selectionFrame = frame;
}
}
function updateStats() {
const obj = objectById.get(selectedId);
const linearPercent = linearFraction(obj.distance) * 100;
const logPercentValue = logFraction(obj.distance);
const logPercent = logPercentValue === null ? null : logPercentValue * 100;
document.getElementById("linearName").textContent = obj.name.toUpperCase();
document.getElementById("logName").textContent = obj.name.toUpperCase();
document.getElementById("linearDistance").textContent = obj.displayDistance;
document.getElementById("logDistance").textContent = obj.displayDistance;
document.getElementById("linearPosition").textContent = formatPercent(linearPercent);
const linearPin = document.getElementById("linearPin");
linearPin.style.left = linearPercent + "%";
linearPin.classList.remove("hidden");
const logPin = document.getElementById("logPin");
if (logPercent === null) {
document.getElementById("logPosition").textContent = "N/A — BELOW 1 AU";
logPin.classList.add("hidden");
} else {
document.getElementById("logPosition").textContent = formatPercent(logPercent);
logPin.style.left = logPercent + "%";
logPin.classList.remove("hidden");
}
for (const [id, card] of cardById) {
card.setAttribute("aria-pressed", String(id === selectedId));
}
}
function selectObject(id, centerCard = false) {
if (!objectById.has(id)) return;
selectedId = id;
for (const view of views) {
for (const [entryId, entry] of view.entries) {
const active = entryId === selectedId;
if (entry.stem) {
entry.stem.material.color.setHex(active ? 0xffd166 : 0x29465f);
entry.stem.scale.x = active ? 2.0 : 1.0;
}
if (entry.axisMarker) {
entry.axisMarker.material.color.setHex(active ? 0xffd166 : 0x3d617e);
entry.axisMarker.scale.set(active ? 1.4 : 1.0, active ? 1.5 : 1.0, active ? 1.2 : 1.0);
}
}
}
updateSelectionFrames();
updateStats();
if (centerCard) {
const card = cardById.get(selectedId);
ledger.scrollTo({
left: Math.max(0, card.offsetLeft - ledger.clientWidth / 2 + card.offsetWidth / 2),
behavior: "smooth"
});
}
}
function pickAt(event) {
const rect = canvas.getBoundingClientRect();
const localX = event.clientX - rect.left;
const localY = event.clientY - rect.top;
const view = views.find(v =>
localX >= v.x && localX <= v.x + v.width &&
localY >= v.y && localY <= v.y + v.height
);
if (!view) return;
pointer.x = ((localX - view.x) / view.width) * 2 - 1;
pointer.y = -(((localY - view.y) / view.height) * 2 - 1);
raycaster.setFromCamera(pointer, view.camera);
const hits = raycaster.intersectObjects(view.pickables, false);
if (hits.length) {
const id = hits[0].object.userData.objectId;
if (id) selectObject(id, true);
}
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
dragMoved = false;
dragStartY = event.clientY;
dragStartPitch = cameraPitch;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaY = event.clientY - dragStartY;
if (Math.abs(deltaY) > 3) dragMoved = true;
cameraPitch = THREE.MathUtils.clamp(dragStartPitch + deltaY * 0.0032, 0.20, 0.90);
views.forEach(updateCamera);
});
canvas.addEventListener("pointerup", event => {
if (!dragMoved) pickAt(event);
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(cameraZoom * Math.exp(-event.deltaY * 0.001), 0.78, 1.45);
views.forEach(updateCamera);
}, { passive: false });
document.getElementById("resetView").addEventListener("click", () => {
cameraPitch = 0.53;
cameraZoom = 1;
views.forEach(updateCamera);
});
document.addEventListener("keydown", event => {
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") return;
const index = objects.findIndex(o => o.id === selectedId);
const delta = event.key === "ArrowRight" ? 1 : -1;
const next = (index + delta + objects.length) % objects.length;
selectObject(objects[next].id, true);
event.preventDefault();
});
function render() {
renderer.setScissorTest(false);
renderer.clear();
renderer.setScissorTest(true);
for (const view of views) {
const bottom = stageHeight - view.y - view.height;
renderer.setViewport(view.x, bottom, view.width, view.height);
renderer.setScissor(view.x, bottom, view.width, view.height);
renderer.render(view.scene, view.camera);
}
}
selectObject("neptune", false);
const initialCard = cardById.get("neptune");
ledger.scrollLeft = Math.max(0, initialCard.offsetLeft - ledger.clientWidth / 2 + initialCard.offsetWidth / 2);
renderer.setAnimationLoop(render);
</script>
</body>
</html>
```