Add the deep-sky backdrop, the last unbuilt piece of the plan
The design doc scopes deep-sky objects as a galaxy-view backdrop and lists fetchDeepSky.ts, deepsky.json and deepsky.model.ts, but none of it existed — it was the only part of the plan with no implementation behind it. ETL: fetchDeepSky.ts pulls the OpenNGC catalog, classifies each object as a galaxy/nebula/cluster, and keeps the ~460 worth drawing (everything Messier, everything with a common name, and anything brighter than magnitude 9) out of ~12,000 mostly-anonymous rows. build.ts runs it and validates the output. Distances are the hard part: OpenNGC has no distance column, and both fallbacks fail for the best-known objects. M31, M33 and M42 are Local Group members whose redshift is negative or absent, and a galaxy's catalog parallax comes from a cross-matched foreground star — 6 mas for M31 would put a 780 kpc galaxy at 167 pc. So records store a unit direction on the celestial sphere rather than a position (the line of sight is always known precisely, and the objects are drawn on a fixed backdrop shell where true distance is unusable anyway), and distance is optional metadata carrying its own provenance. Parallax is trusted only for galactic objects, redshift only above z=0.003 where expansion outweighs peculiar velocity. 330 of 463 get a distance; the rest honestly report none. Rendering: DeepSkyRenderer paints the objects as soft additive billboards on a 2500 pc shell — clear of the 50 pc star field, beyond the camera's 2000 pc orbit limit, and inside its 5000 pc far plane. Size comes from real angular extent, so Andromeda is six times wider than the full Moon, clamped at both ends. Sprites rather than points because the WebGPU backend caps point primitives at one pixel; materials are shared per kind and brightness band, so 460 objects cost nine of them. The brightest dozen get permanent labels, which needed the label overlay to accept string ids alongside numeric star ids. The backdrop is decorative, so a failure to load its dataset is logged and the star field comes up regardless. Also documents the app in the README, which until now covered only the plugin marketplace. Tests: 112 passing, up from 54. Build, both typechecks and the Playwright suite are green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WaySiNst4HhDXBHnMy8p5G
This commit is contained in:
@@ -22,12 +22,41 @@ export function applyMilkyWaySkybox(scene: THREE.Scene, path: string): void {
|
||||
const glowSpriteCache = new Map<string, THREE.Texture>();
|
||||
|
||||
/**
|
||||
* A soft radial-gradient canvas texture, cached per color, used to fake atmosphere/corona glow.
|
||||
* Returns `undefined` if 2D canvas rendering isn't available (e.g. under a test/jsdom
|
||||
* environment with no canvas backend) so callers can fall back to a flat-color sprite instead.
|
||||
* Falloff shapes for {@link createGlowTexture}.
|
||||
*
|
||||
* `corona` is a tight, bright core for a star's or planet's halo, where the light really does
|
||||
* come from a small hot source. `diffuse` is a much softer, dimmer profile for deep-sky
|
||||
* objects, which are extended clouds — the same tight curve turns them into hard-edged
|
||||
* billiard balls that read as solid geometry rather than as haze.
|
||||
*/
|
||||
function glowSpriteTexture(color: THREE.ColorRepresentation): THREE.Texture | undefined {
|
||||
const key = new THREE.Color(color).getHexString();
|
||||
export type GlowProfile = 'corona' | 'diffuse';
|
||||
|
||||
const GLOW_PROFILES: Readonly<Record<GlowProfile, readonly { offset: number; alpha: number }[]>> = {
|
||||
corona: [
|
||||
{ offset: 0, alpha: 0.85 },
|
||||
{ offset: 0.4, alpha: 0.35 },
|
||||
{ offset: 1, alpha: 0 }
|
||||
],
|
||||
diffuse: [
|
||||
{ offset: 0, alpha: 0.5 },
|
||||
{ offset: 0.18, alpha: 0.34 },
|
||||
{ offset: 0.45, alpha: 0.13 },
|
||||
{ offset: 0.75, alpha: 0.03 },
|
||||
{ offset: 1, alpha: 0 }
|
||||
]
|
||||
};
|
||||
|
||||
/**
|
||||
* A soft radial-gradient canvas texture, cached per color and profile, used to fake
|
||||
* atmosphere/corona glow and to paint deep-sky objects on the galaxy backdrop. Returns
|
||||
* `undefined` if 2D canvas rendering isn't available (e.g. under a test/jsdom environment with
|
||||
* no canvas backend) so callers can fall back to a flat-color sprite instead.
|
||||
*
|
||||
* The cache is process-wide and intentionally not disposed: there is one texture per distinct
|
||||
* color/profile pair, they are tiny, and they outlive any individual scene.
|
||||
*/
|
||||
export function createGlowTexture(color: THREE.ColorRepresentation, profile: GlowProfile = 'corona'): THREE.Texture | undefined {
|
||||
const key = `${new THREE.Color(color).getHexString()}:${profile}`;
|
||||
const cached = glowSpriteCache.get(key);
|
||||
if (cached) {
|
||||
return cached;
|
||||
@@ -46,9 +75,9 @@ function glowSpriteTexture(color: THREE.ColorRepresentation): THREE.Texture | un
|
||||
const [r, g, b] = [Math.round(rgb.r * 255), Math.round(rgb.g * 255), Math.round(rgb.b * 255)];
|
||||
|
||||
const gradient = context.createRadialGradient(size / 2, size / 2, 0, size / 2, size / 2, size / 2);
|
||||
gradient.addColorStop(0, `rgba(${r}, ${g}, ${b}, 0.85)`);
|
||||
gradient.addColorStop(0.4, `rgba(${r}, ${g}, ${b}, 0.35)`);
|
||||
gradient.addColorStop(1, `rgba(${r}, ${g}, ${b}, 0)`);
|
||||
for (const stop of GLOW_PROFILES[profile]) {
|
||||
gradient.addColorStop(stop.offset, `rgba(${r}, ${g}, ${b}, ${stop.alpha})`);
|
||||
}
|
||||
context.fillStyle = gradient;
|
||||
context.fillRect(0, 0, size, size);
|
||||
|
||||
@@ -66,7 +95,7 @@ function glowSpriteTexture(color: THREE.ColorRepresentation): THREE.Texture | un
|
||||
*/
|
||||
export function createGlowSprite(color: THREE.ColorRepresentation, radius: number, scale: number): THREE.Sprite {
|
||||
const material = new THREE.SpriteMaterial({
|
||||
map: glowSpriteTexture(color),
|
||||
map: createGlowTexture(color),
|
||||
color: color,
|
||||
transparent: true,
|
||||
depthWrite: false,
|
||||
|
||||
Reference in New Issue
Block a user