@motioncomplex/cosmos-lib 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +125 -0
- package/dist/api.d.ts +246 -0
- package/dist/cache.d.ts +11 -0
- package/dist/clock.d.ts +181 -0
- package/dist/constants.d.ts +43 -0
- package/dist/data/constellations.d.ts +58 -0
- package/dist/data/cutouts.d.ts +70 -0
- package/dist/data/deep-sky.d.ts +27 -0
- package/dist/data/images.d.ts +147 -0
- package/dist/data/index.d.ts +422 -0
- package/dist/data/messier.d.ts +61 -0
- package/dist/data/ps1-files.d.ts +11 -0
- package/dist/data/showers.d.ts +62 -0
- package/dist/data/solar-system.d.ts +34 -0
- package/dist/data/stars.d.ts +57 -0
- package/dist/data/textures.d.ts +67 -0
- package/dist/eclipse.d.ts +176 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +713 -0
- package/dist/math.d.ts +532 -0
- package/dist/media-DVOcIMa1.js +252 -0
- package/dist/media-DlE7RKBL.cjs +1 -0
- package/dist/media.d.ts +217 -0
- package/dist/moon.d.ts +170 -0
- package/dist/planner.d.ts +224 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.ts +167 -0
- package/dist/react/index.js +163 -0
- package/dist/skymap-hittest.d.ts +69 -0
- package/dist/skymap-interactive-CLg6FA0X.js +6377 -0
- package/dist/skymap-interactive-D2OZFwJ7.cjs +1 -0
- package/dist/skymap-interactive.d.ts +153 -0
- package/dist/skymap.d.ts +172 -0
- package/dist/sun.d.ts +119 -0
- package/dist/three/factories.d.ts +160 -0
- package/dist/three/flight.d.ts +116 -0
- package/dist/three/index.cjs +20 -0
- package/dist/three/index.d.ts +21 -0
- package/dist/three/index.js +404 -0
- package/dist/three/lod.d.ts +100 -0
- package/dist/three/shaders.d.ts +22 -0
- package/dist/three/types.d.ts +169 -0
- package/dist/transitions.d.ts +246 -0
- package/dist/types.d.ts +730 -0
- package/dist/units.d.ts +132 -0
- package/package.json +93 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { CelestialObject, EquatorialCoord, InteractiveSkyMapOptions, ObserverParams, FOVOverlayOptions, SkyMapEventMap, SkyMapViewState } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interactive sky map that wraps a `<canvas>` element with pan, zoom,
|
|
4
|
+
* click-to-identify, hover detection, FOV overlays, a configurable HUD,
|
|
5
|
+
* and optional real-time sidereal tracking.
|
|
6
|
+
*
|
|
7
|
+
* Renders via the existing {@link renderSkyMap} for the base layer, then
|
|
8
|
+
* overlays interactive highlights and HUD elements on top.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createInteractiveSkyMap, Data } from '@motioncomplex/cosmos-lib'
|
|
13
|
+
*
|
|
14
|
+
* const skymap = createInteractiveSkyMap(canvas, Data.all(), {
|
|
15
|
+
* projection: 'stereographic',
|
|
16
|
+
* center: { ra: 83.8, dec: -5.4 },
|
|
17
|
+
* scale: 400,
|
|
18
|
+
* panEnabled: true,
|
|
19
|
+
* zoomEnabled: true,
|
|
20
|
+
* fov: { radiusDeg: 5, label: 'Telescope' },
|
|
21
|
+
* })
|
|
22
|
+
*
|
|
23
|
+
* skymap.on('select', ({ object }) => console.log(object.name))
|
|
24
|
+
* skymap.on('viewchange', ({ center, scale }) => updateURL(center, scale))
|
|
25
|
+
*
|
|
26
|
+
* // Later:
|
|
27
|
+
* skymap.dispose()
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class InteractiveSkyMap {
|
|
31
|
+
private _canvas;
|
|
32
|
+
private _ctx;
|
|
33
|
+
private _objects;
|
|
34
|
+
private _opts;
|
|
35
|
+
private _view;
|
|
36
|
+
private _projectedCache;
|
|
37
|
+
private _selectedObject;
|
|
38
|
+
private _hoveredObject;
|
|
39
|
+
private _listeners;
|
|
40
|
+
private _rafId;
|
|
41
|
+
private _dirty;
|
|
42
|
+
private _realTimeTimer;
|
|
43
|
+
private _pointers;
|
|
44
|
+
private _abortController;
|
|
45
|
+
private _disposed;
|
|
46
|
+
private _panAnimId;
|
|
47
|
+
constructor(canvas: HTMLCanvasElement, objects: CelestialObject[], opts?: InteractiveSkyMapOptions);
|
|
48
|
+
/**
|
|
49
|
+
* Subscribe to an interaction event.
|
|
50
|
+
*
|
|
51
|
+
* @param event - Event name (`'select'`, `'hover'`, or `'viewchange'`).
|
|
52
|
+
* @param handler - Callback invoked when the event fires.
|
|
53
|
+
*/
|
|
54
|
+
on<K extends keyof SkyMapEventMap>(event: K, handler: (data: SkyMapEventMap[K]) => void): void;
|
|
55
|
+
/**
|
|
56
|
+
* Unsubscribe from an interaction event.
|
|
57
|
+
*/
|
|
58
|
+
off<K extends keyof SkyMapEventMap>(event: K, handler: (data: SkyMapEventMap[K]) => void): void;
|
|
59
|
+
private _emit;
|
|
60
|
+
/** Get the current view state. */
|
|
61
|
+
getView(): Readonly<SkyMapViewState>;
|
|
62
|
+
/**
|
|
63
|
+
* Programmatically set the view centre, scale, and/or projection.
|
|
64
|
+
* Triggers a re-render and emits `'viewchange'`.
|
|
65
|
+
*/
|
|
66
|
+
setView(view: Partial<SkyMapViewState>): void;
|
|
67
|
+
/**
|
|
68
|
+
* Animate the view to a new centre and/or scale.
|
|
69
|
+
*
|
|
70
|
+
* @param center - Target centre in equatorial coordinates.
|
|
71
|
+
* @param opts.scale - Target scale (optional, defaults to current).
|
|
72
|
+
* @param opts.durationMs - Animation duration in ms (default 800).
|
|
73
|
+
*/
|
|
74
|
+
panTo(center: EquatorialCoord, opts?: {
|
|
75
|
+
scale?: number;
|
|
76
|
+
durationMs?: number;
|
|
77
|
+
}): void;
|
|
78
|
+
/** The currently selected object, or `null`. */
|
|
79
|
+
get selectedObject(): CelestialObject | null;
|
|
80
|
+
/** The currently hovered object, or `null`. */
|
|
81
|
+
get hoveredObject(): CelestialObject | null;
|
|
82
|
+
/**
|
|
83
|
+
* Programmatically select an object by its `id`. Pass `null` to clear.
|
|
84
|
+
*/
|
|
85
|
+
select(objectId: string | null): void;
|
|
86
|
+
/**
|
|
87
|
+
* Return the celestial object at a given canvas pixel position, or `null`.
|
|
88
|
+
*/
|
|
89
|
+
objectAt(canvasX: number, canvasY: number): CelestialObject | null;
|
|
90
|
+
/** Replace the objects array and re-render. */
|
|
91
|
+
setObjects(objects: CelestialObject[]): void;
|
|
92
|
+
/** Merge new options and re-render. */
|
|
93
|
+
setOptions(opts: Partial<InteractiveSkyMapOptions>): void;
|
|
94
|
+
/** Set or clear the FOV indicator overlay(s). */
|
|
95
|
+
setFOV(fov: FOVOverlayOptions | FOVOverlayOptions[] | null): void;
|
|
96
|
+
/**
|
|
97
|
+
* Start real-time sidereal tracking. The view centre follows the local
|
|
98
|
+
* sidereal time so the sky drifts naturally.
|
|
99
|
+
*
|
|
100
|
+
* @param observer - Observer parameters. If omitted, uses the value from
|
|
101
|
+
* {@link InteractiveSkyMapOptions.observer}.
|
|
102
|
+
* @throws If no observer parameters are available.
|
|
103
|
+
*/
|
|
104
|
+
startRealTime(observer?: ObserverParams): void;
|
|
105
|
+
/** Stop real-time sidereal tracking. */
|
|
106
|
+
stopRealTime(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Force an immediate re-render. Normally renders happen automatically
|
|
109
|
+
* via the dirty-flag mechanism; call this only if you need a synchronous
|
|
110
|
+
* update.
|
|
111
|
+
*/
|
|
112
|
+
render(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Remove all event listeners, cancel animations, and release resources.
|
|
115
|
+
* The instance should not be used after calling `dispose()`.
|
|
116
|
+
*/
|
|
117
|
+
dispose(): void;
|
|
118
|
+
/** Convert a pointer event to canvas-space coordinates (DPI-aware). */
|
|
119
|
+
private _canvasCoords;
|
|
120
|
+
private _onPointerDown;
|
|
121
|
+
private _onPointerMove;
|
|
122
|
+
private _onPointerUp;
|
|
123
|
+
private _onWheel;
|
|
124
|
+
private _markDirty;
|
|
125
|
+
private _clampScale;
|
|
126
|
+
private _emitViewChange;
|
|
127
|
+
/**
|
|
128
|
+
* Unified forward-project helper (same logic as renderSkyMap's internal
|
|
129
|
+
* `project` function) returning absolute canvas coordinates.
|
|
130
|
+
*/
|
|
131
|
+
private _project;
|
|
132
|
+
/** Rebuild the projected-object cache used for hit-testing and highlights. */
|
|
133
|
+
private _rebuildProjectedCache;
|
|
134
|
+
/** Draw a highlight ring around a specific object. */
|
|
135
|
+
private _drawHighlight;
|
|
136
|
+
/** Draw FOV indicator overlay(s). */
|
|
137
|
+
private _drawFOV;
|
|
138
|
+
/** Draw HUD elements (cardinal labels, horizon line, zenith marker). */
|
|
139
|
+
private _drawHUD;
|
|
140
|
+
private _realTimeLoop;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Create an {@link InteractiveSkyMap} on the given canvas.
|
|
144
|
+
*
|
|
145
|
+
* This is a convenience wrapper around the class constructor for consumers
|
|
146
|
+
* who prefer a functional style.
|
|
147
|
+
*
|
|
148
|
+
* @param canvas - Target `<canvas>` element.
|
|
149
|
+
* @param objects - Celestial objects to render (e.g. `Data.all()`).
|
|
150
|
+
* @param opts - Interactive sky map options.
|
|
151
|
+
* @returns A new {@link InteractiveSkyMap} instance.
|
|
152
|
+
*/
|
|
153
|
+
export declare function createInteractiveSkyMap(canvas: HTMLCanvasElement, objects: CelestialObject[], opts?: InteractiveSkyMapOptions): InteractiveSkyMap;
|
package/dist/skymap.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { EquatorialCoord, ProjectedPoint, SkyMapRenderOptions } from './types.js';
|
|
2
|
+
import type { CelestialObject } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Stereographic projection centred on `center`.
|
|
5
|
+
*
|
|
6
|
+
* Good for detailed star charts around a specific point. Preserves angles
|
|
7
|
+
* (conformal) but distorts areas away from the centre. Returns offsets in
|
|
8
|
+
* pixels relative to the canvas centre.
|
|
9
|
+
*
|
|
10
|
+
* @param coord - Equatorial coordinates (RA/Dec in degrees) of the point to project.
|
|
11
|
+
* @param center - Equatorial coordinates of the projection centre.
|
|
12
|
+
* @param scale - Pixel scale factor applied to the projection. Higher values zoom in.
|
|
13
|
+
* Defaults to `500`.
|
|
14
|
+
* @returns A {@link ProjectedPoint} with `x`/`y` offsets from canvas centre and a
|
|
15
|
+
* `visible` flag (`false` when the point is on the far side of the sphere).
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { stereographic } from '@motioncomplex/cosmos-lib'
|
|
20
|
+
*
|
|
21
|
+
* // Project Betelgeuse relative to the centre of Orion
|
|
22
|
+
* const orionCenter = { ra: 83.8, dec: 1.2 }
|
|
23
|
+
* const betelgeuse = { ra: 88.79, dec: 7.41 }
|
|
24
|
+
* const pt = stereographic(betelgeuse, orionCenter, 600)
|
|
25
|
+
* // pt.x / pt.y are pixel offsets; pt.visible === true
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function stereographic(coord: EquatorialCoord, center: EquatorialCoord, scale?: number): ProjectedPoint;
|
|
29
|
+
/**
|
|
30
|
+
* Mollweide (equal-area) projection.
|
|
31
|
+
*
|
|
32
|
+
* Suited to full-sky maps where preserving relative area is important.
|
|
33
|
+
* Unlike the stereographic and gnomonic projections, this returns
|
|
34
|
+
* **absolute** pixel coordinates rather than offsets from centre.
|
|
35
|
+
* Internally solves the auxiliary angle with Newton-Raphson iteration.
|
|
36
|
+
*
|
|
37
|
+
* @param coord - Equatorial coordinates (RA/Dec in degrees) of the point to project.
|
|
38
|
+
* @param canvas - Dimensions of the target canvas (`{ width, height }` in pixels).
|
|
39
|
+
* @returns A {@link ProjectedPoint} with absolute `x`/`y` pixel coordinates.
|
|
40
|
+
* The `visible` flag is always `true` for Mollweide (full-sky coverage).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { mollweide } from '@motioncomplex/cosmos-lib'
|
|
45
|
+
*
|
|
46
|
+
* // Project Polaris onto an 800x400 all-sky canvas
|
|
47
|
+
* const polaris = { ra: 37.95, dec: 89.26 }
|
|
48
|
+
* const pt = mollweide(polaris, { width: 800, height: 400 })
|
|
49
|
+
* ctx.fillRect(pt.x - 2, pt.y - 2, 4, 4)
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function mollweide(coord: EquatorialCoord, canvas: {
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
}): ProjectedPoint;
|
|
56
|
+
/**
|
|
57
|
+
* Gnomonic (tangent-plane) projection.
|
|
58
|
+
*
|
|
59
|
+
* Minimal distortion near the centre; commonly used for telescope
|
|
60
|
+
* field-of-view charts and narrow-field imaging. Great circles are
|
|
61
|
+
* projected as straight lines, but the usable area is limited to
|
|
62
|
+
* roughly a hemisphere. Returns offsets in pixels relative to the
|
|
63
|
+
* canvas centre.
|
|
64
|
+
*
|
|
65
|
+
* @param coord - Equatorial coordinates (RA/Dec in degrees) of the point to project.
|
|
66
|
+
* @param center - Equatorial coordinates of the tangent point (projection centre).
|
|
67
|
+
* @param scale - Pixel scale factor applied to the projection. Defaults to `400`.
|
|
68
|
+
* @returns A {@link ProjectedPoint} with `x`/`y` offsets from canvas centre.
|
|
69
|
+
* `visible` is `false` when the point falls behind the tangent plane.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { gnomonic } from '@motioncomplex/cosmos-lib'
|
|
74
|
+
*
|
|
75
|
+
* // Project the Orion Nebula (M42) relative to Orion's belt centre
|
|
76
|
+
* const beltCenter = { ra: 84.05, dec: -1.2 }
|
|
77
|
+
* const m42 = { ra: 83.82, dec: -5.39 }
|
|
78
|
+
* const pt = gnomonic(m42, beltCenter, 500)
|
|
79
|
+
* if (pt.visible) {
|
|
80
|
+
* ctx.arc(cx + pt.x, cy - pt.y, 4, 0, Math.PI * 2)
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function gnomonic(coord: EquatorialCoord, center: EquatorialCoord, scale?: number): ProjectedPoint;
|
|
85
|
+
/**
|
|
86
|
+
* Map a {@link CelestialObject} to a CSS colour string based on its spectral
|
|
87
|
+
* class (for stars) or object type (nebula, galaxy, cluster, black hole).
|
|
88
|
+
*
|
|
89
|
+
* @internal Not part of the public API -- used by {@link renderSkyMap}.
|
|
90
|
+
* @param obj - The celestial object to colour.
|
|
91
|
+
* @returns A CSS hex colour string (e.g. `'#9bb0ff'` for an O-type star).
|
|
92
|
+
*/
|
|
93
|
+
export declare function spectralColor(obj: CelestialObject): string;
|
|
94
|
+
/**
|
|
95
|
+
* Render an interactive sky chart onto a `<canvas>` element.
|
|
96
|
+
*
|
|
97
|
+
* Draws a coordinate grid (RA/Dec), constellation stick-figure lines and
|
|
98
|
+
* labels, and all supplied celestial objects -- each rendered with a shape
|
|
99
|
+
* and colour appropriate to its type (star glow, galaxy ellipse, nebula
|
|
100
|
+
* square, cluster circle). Stars brighter than magnitude 3.5 are labelled
|
|
101
|
+
* automatically when `showLabels` is enabled.
|
|
102
|
+
*
|
|
103
|
+
* Supports three projection modes via {@link SkyMapRenderOptions.projection}:
|
|
104
|
+
* `'stereographic'` (default), `'mollweide'`, and `'gnomonic'`.
|
|
105
|
+
*
|
|
106
|
+
* @param canvas - The target `HTMLCanvasElement` to draw on. Must support a
|
|
107
|
+
* 2D rendering context.
|
|
108
|
+
* @param objects - Array of {@link CelestialObject} entries to plot (e.g. from
|
|
109
|
+
* `Data.all()` or `Data.search()`). Objects with `null` RA/Dec
|
|
110
|
+
* or magnitudes above `showMagnitudeLimit` are skipped.
|
|
111
|
+
* @param opts - Render options controlling projection, grid, labels,
|
|
112
|
+
* magnitude limit, colours, and constellation overlays.
|
|
113
|
+
* See {@link SkyMapRenderOptions} for defaults.
|
|
114
|
+
* @throws If the canvas does not support a 2D context.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import { renderSkyMap } from '@motioncomplex/cosmos-lib'
|
|
119
|
+
* import { Data } from '@motioncomplex/cosmos-lib'
|
|
120
|
+
*
|
|
121
|
+
* const canvas = document.querySelector<HTMLCanvasElement>('#sky')!
|
|
122
|
+
* canvas.width = 1200
|
|
123
|
+
* canvas.height = 800
|
|
124
|
+
*
|
|
125
|
+
* // Render the Orion region with a stereographic projection
|
|
126
|
+
* renderSkyMap(canvas, Data.all(), {
|
|
127
|
+
* projection: 'stereographic',
|
|
128
|
+
* center: { ra: 83.8, dec: 1.2 }, // centre of Orion
|
|
129
|
+
* scale: 400,
|
|
130
|
+
* showGrid: true,
|
|
131
|
+
* showLabels: true,
|
|
132
|
+
* showMagnitudeLimit: 6,
|
|
133
|
+
* background: '#0a0a18',
|
|
134
|
+
* })
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* // Full-sky Mollweide map
|
|
140
|
+
* renderSkyMap(canvas, Data.all(), {
|
|
141
|
+
* projection: 'mollweide',
|
|
142
|
+
* showGrid: true,
|
|
143
|
+
* showLabels: true,
|
|
144
|
+
* showMagnitudeLimit: 5,
|
|
145
|
+
* })
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function renderSkyMap(canvas: HTMLCanvasElement, objects: CelestialObject[], opts?: SkyMapRenderOptions): void;
|
|
149
|
+
/**
|
|
150
|
+
* Legacy namespace re-exporting all sky-map functions.
|
|
151
|
+
*
|
|
152
|
+
* @deprecated Use the named exports `stereographic`, `mollweide`, `gnomonic`,
|
|
153
|
+
* and `renderSkyMap` directly instead. This object is retained solely for
|
|
154
|
+
* backwards compatibility and will be removed in a future major release.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* // Before (deprecated)
|
|
159
|
+
* import { SkyMap } from '@motioncomplex/cosmos-lib'
|
|
160
|
+
* SkyMap.render(canvas, objects)
|
|
161
|
+
*
|
|
162
|
+
* // After (preferred)
|
|
163
|
+
* import { renderSkyMap } from '@motioncomplex/cosmos-lib'
|
|
164
|
+
* renderSkyMap(canvas, objects)
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare const SkyMap: {
|
|
168
|
+
stereographic: typeof stereographic;
|
|
169
|
+
mollweide: typeof mollweide;
|
|
170
|
+
gnomonic: typeof gnomonic;
|
|
171
|
+
render: typeof renderSkyMap;
|
|
172
|
+
};
|
package/dist/sun.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { ObserverParams, SunPosition, TwilightTimes } from './types.js';
|
|
2
|
+
export declare const Sun: {
|
|
3
|
+
/**
|
|
4
|
+
* Geocentric equatorial position of the Sun.
|
|
5
|
+
*
|
|
6
|
+
* Computes the Sun's right ascension, declination, distance, and ecliptic longitude
|
|
7
|
+
* for the given date. The position includes nutation corrections and uses the true
|
|
8
|
+
* obliquity of the ecliptic for the equatorial conversion.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Accuracy is approximately 0.01° for dates within a few centuries of J2000.0 (2000-01-01 12:00 TT).
|
|
12
|
+
* The algorithm derives geocentric solar coordinates by inverting the heliocentric Earth
|
|
13
|
+
* position from VSOP87 theory.
|
|
14
|
+
*
|
|
15
|
+
* @param date - The date and time for which to compute the Sun's position. Defaults to the current date/time.
|
|
16
|
+
* @returns The Sun's geocentric equatorial position including RA (0-360°), declination, distance in AU, and ecliptic longitude.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { Sun } from '@motioncomplex/cosmos-lib'
|
|
21
|
+
*
|
|
22
|
+
* // Sun position at the 2024 vernal equinox
|
|
23
|
+
* const pos = Sun.position(new Date('2024-03-20T03:06:00Z'))
|
|
24
|
+
* console.log(`RA: ${pos.ra.toFixed(4)}°`) // ~0° (vernal equinox point)
|
|
25
|
+
* console.log(`Dec: ${pos.dec.toFixed(4)}°`) // ~0° at equinox
|
|
26
|
+
* console.log(`Distance: ${pos.distance_AU} AU`) // ~0.996 AU
|
|
27
|
+
* console.log(`Ecliptic Lon: ${pos.eclipticLon.toFixed(4)}°`) // ~0° at equinox
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
readonly position: (date?: Date) => SunPosition;
|
|
31
|
+
/**
|
|
32
|
+
* Solar noon (transit) for a given observer.
|
|
33
|
+
*
|
|
34
|
+
* Computes the time at which the Sun crosses the observer's local meridian,
|
|
35
|
+
* reaching its highest altitude for the day.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Uses the standard solar altitude of -0.8333° which accounts for atmospheric
|
|
39
|
+
* refraction (34 arc-minutes) and the Sun's mean semi-diameter (16 arc-minutes).
|
|
40
|
+
*
|
|
41
|
+
* @param obs - Observer location and optional date. If `obs.date` is omitted, the current date/time is used.
|
|
42
|
+
* @returns A `Date` representing the moment of solar noon (local meridian transit).
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { Sun } from '@motioncomplex/cosmos-lib'
|
|
47
|
+
*
|
|
48
|
+
* // Solar noon in London on the vernal equinox
|
|
49
|
+
* const noon = Sun.solarNoon({ lat: 51.5, lng: -0.1, date: new Date('2024-03-20') })
|
|
50
|
+
* console.log('Solar noon:', noon.toISOString()) // ~12:10 UTC
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
readonly solarNoon: (obs: ObserverParams) => Date;
|
|
54
|
+
/**
|
|
55
|
+
* Equation of time in minutes.
|
|
56
|
+
*
|
|
57
|
+
* Computes the difference between apparent solar time and mean solar time.
|
|
58
|
+
* A positive value means the true Sun is ahead of the mean Sun (sundial reads
|
|
59
|
+
* later than clock time), and a negative value means it trails behind.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* The equation of time arises from the eccentricity of Earth's orbit and
|
|
63
|
+
* the obliquity of the ecliptic. It varies between approximately -14 and +16 minutes
|
|
64
|
+
* over the course of a year. The computation uses the Sun's mean longitude (L0)
|
|
65
|
+
* and apparent right ascension, converting the angular difference to minutes of time
|
|
66
|
+
* at 4 minutes per degree.
|
|
67
|
+
*
|
|
68
|
+
* @param date - The date and time for the calculation. Defaults to the current date/time.
|
|
69
|
+
* @returns The equation of time in minutes. Positive means the apparent Sun is ahead of mean time.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { Sun } from '@motioncomplex/cosmos-lib'
|
|
74
|
+
*
|
|
75
|
+
* // EoT at the vernal equinox 2024 (should be near -7 minutes)
|
|
76
|
+
* const eot = Sun.equationOfTime(new Date('2024-03-20'))
|
|
77
|
+
* console.log(`Equation of Time: ${eot.toFixed(2)} minutes`)
|
|
78
|
+
*
|
|
79
|
+
* // EoT varies through the year; check the November maximum
|
|
80
|
+
* const eotNov = Sun.equationOfTime(new Date('2024-11-03'))
|
|
81
|
+
* console.log(`EoT in November: ${eotNov.toFixed(2)} minutes`) // ~+16 min
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
readonly equationOfTime: (date?: Date) => number;
|
|
85
|
+
/**
|
|
86
|
+
* Complete twilight times for an observer.
|
|
87
|
+
*
|
|
88
|
+
* Returns sunrise/sunset plus civil, nautical, and astronomical twilight
|
|
89
|
+
* boundaries for the given observer location and date. Each twilight boundary
|
|
90
|
+
* corresponds to the Sun's centre reaching a specific altitude below the horizon.
|
|
91
|
+
*
|
|
92
|
+
* @remarks
|
|
93
|
+
* Standard solar altitudes used for each twilight type:
|
|
94
|
+
* - **Sunrise/Sunset**: -0.8333° (accounts for refraction and solar semi-diameter)
|
|
95
|
+
* - **Civil twilight**: -6° (sufficient light for outdoor activities without artificial lighting)
|
|
96
|
+
* - **Nautical twilight**: -12° (horizon still discernible at sea)
|
|
97
|
+
* - **Astronomical twilight**: -18° (sky fully dark for astronomical observations)
|
|
98
|
+
*
|
|
99
|
+
* At polar latitudes, some or all twilight phases may not occur on a given date.
|
|
100
|
+
* In such cases the corresponding fields will be `null`.
|
|
101
|
+
*
|
|
102
|
+
* @param obs - Observer location and optional date. If `obs.date` is omitted, the current date/time is used.
|
|
103
|
+
* @returns An object containing all nine twilight timestamps, from astronomical dawn through astronomical dusk.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { Sun } from '@motioncomplex/cosmos-lib'
|
|
108
|
+
*
|
|
109
|
+
* // Twilight times in London on the 2024 vernal equinox
|
|
110
|
+
* const tw = Sun.twilight({ lat: 51.5, lng: -0.1, date: new Date('2024-03-20') })
|
|
111
|
+
* console.log('Astronomical dawn:', tw.astronomicalDawn?.toISOString())
|
|
112
|
+
* console.log('Sunrise:', tw.sunrise?.toISOString())
|
|
113
|
+
* console.log('Solar noon:', tw.solarNoon.toISOString())
|
|
114
|
+
* console.log('Sunset:', tw.sunset?.toISOString())
|
|
115
|
+
* console.log('Astronomical dusk:', tw.astronomicalDusk?.toISOString())
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
readonly twilight: (obs: ObserverParams) => TwilightTimes;
|
|
119
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type * as THREE from 'three';
|
|
2
|
+
import type { PlanetOptions, PlanetResult, NebulaOptions, NebulaResult, StarFieldOptions, OrbitOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Create a planet or star mesh with optional textures, bump maps,
|
|
5
|
+
* atmospheric glow, and ring systems.
|
|
6
|
+
*
|
|
7
|
+
* The returned group contains the sphere mesh and any extras (atmosphere shell,
|
|
8
|
+
* ring geometry). Call `dispose()` on the result when removing the planet from
|
|
9
|
+
* the scene to free all GPU resources.
|
|
10
|
+
*
|
|
11
|
+
* @param opts - Planet configuration (radius, textures, atmosphere, rings, etc.).
|
|
12
|
+
* @param THREE - The Three.js module, passed at runtime to avoid a hard dependency
|
|
13
|
+
* on `three` in the library bundle.
|
|
14
|
+
* @returns A {@link PlanetResult} containing the `group`, the surface `mesh`, and
|
|
15
|
+
* a `dispose` function.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import * as THREE from 'three'
|
|
20
|
+
* import { createPlanet } from '@motioncomplex/cosmos-lib/three'
|
|
21
|
+
*
|
|
22
|
+
* const { group, mesh, dispose } = createPlanet({
|
|
23
|
+
* radius: 6.5,
|
|
24
|
+
* textureUrl: '/textures/earth-bluemarble-4k.jpg',
|
|
25
|
+
* bumpUrl: '/textures/earth-bump.jpg',
|
|
26
|
+
* atmosphere: { color: 0x4488ff, intensity: 1.3 },
|
|
27
|
+
* rings: { inner: 1.2, outer: 2.0, color: 0xaaaaaa, opacity: 0.6 },
|
|
28
|
+
* }, THREE)
|
|
29
|
+
*
|
|
30
|
+
* scene.add(group)
|
|
31
|
+
* // later, when removing:
|
|
32
|
+
* scene.remove(group)
|
|
33
|
+
* dispose()
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPlanet(opts: PlanetOptions, THREE: typeof import('three')): PlanetResult;
|
|
37
|
+
/**
|
|
38
|
+
* Create a nebula or galaxy sprite using additive blending.
|
|
39
|
+
*
|
|
40
|
+
* Attempts each URL in `textureUrls` in order via {@link Media.chainLoad},
|
|
41
|
+
* applying the first texture that loads successfully. An invisible hit-mesh
|
|
42
|
+
* is added alongside the sprite so the nebula can be raycasted for click
|
|
43
|
+
* detection despite being a billboard.
|
|
44
|
+
*
|
|
45
|
+
* @param opts - Nebula configuration (radius, texture URLs, opacity, aspect ratio).
|
|
46
|
+
* @param THREE - The Three.js module, passed at runtime to avoid a hard dependency
|
|
47
|
+
* on `three` in the library bundle.
|
|
48
|
+
* @returns A {@link NebulaResult} containing the `group`, the `sprite`, an invisible
|
|
49
|
+
* `hitMesh` for raycasting, and a `dispose` function.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import * as THREE from 'three'
|
|
54
|
+
* import { createNebula } from '@motioncomplex/cosmos-lib/three'
|
|
55
|
+
*
|
|
56
|
+
* const { group, hitMesh, dispose } = createNebula({
|
|
57
|
+
* radius: 3000,
|
|
58
|
+
* textureUrls: [
|
|
59
|
+
* 'https://cdn.example.com/orion-hubble.jpg',
|
|
60
|
+
* '/fallback/orion-low.jpg',
|
|
61
|
+
* ],
|
|
62
|
+
* opacity: 0.9,
|
|
63
|
+
* }, THREE)
|
|
64
|
+
*
|
|
65
|
+
* scene.add(group)
|
|
66
|
+
*
|
|
67
|
+
* // Use hitMesh for raycasting
|
|
68
|
+
* raycaster.intersectObject(hitMesh)
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function createNebula(opts: NebulaOptions, THREE: typeof import('three')): NebulaResult;
|
|
72
|
+
/**
|
|
73
|
+
* Create an atmospheric glow rim around a sphere.
|
|
74
|
+
*
|
|
75
|
+
* Renders a slightly larger back-face sphere with a custom Fresnel-based shader
|
|
76
|
+
* and additive blending, producing a soft halo effect. Typically called
|
|
77
|
+
* internally by {@link createPlanet} when `atmosphere` is specified, but can
|
|
78
|
+
* also be used standalone.
|
|
79
|
+
*
|
|
80
|
+
* The mesh stores its disposable resources in `mesh.userData._toDispose`.
|
|
81
|
+
*
|
|
82
|
+
* @param radius - Radius of the parent sphere. The atmosphere shell is
|
|
83
|
+
* generated at `radius * 1.06`.
|
|
84
|
+
* @param colorHex - Glow colour as a hex number (e.g. `0x4488ff`).
|
|
85
|
+
* @param THREE - The Three.js module, passed at runtime to avoid a hard
|
|
86
|
+
* dependency on `three` in the library bundle.
|
|
87
|
+
* @param intensity - Glow intensity multiplier.
|
|
88
|
+
* @returns A `THREE.Mesh` with the atmospheric glow shader applied.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import * as THREE from 'three'
|
|
93
|
+
* import { createAtmosphere } from '@motioncomplex/cosmos-lib/three'
|
|
94
|
+
*
|
|
95
|
+
* const atm = createAtmosphere(6.5, 0x4488ff, THREE, 1.4)
|
|
96
|
+
* scene.add(atm)
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function createAtmosphere(radius: number, colorHex: number, THREE: typeof import('three'), intensity?: number): THREE.Mesh;
|
|
100
|
+
/**
|
|
101
|
+
* Create a randomised star-field point cloud.
|
|
102
|
+
*
|
|
103
|
+
* Generates `count` points distributed uniformly on a spherical shell between
|
|
104
|
+
* `minRadius` and `maxRadius`. Each star is given a randomised colour
|
|
105
|
+
* (warm white, cool blue, or neutral) and brightness for a natural look.
|
|
106
|
+
*
|
|
107
|
+
* Call `points.userData.dispose()` when removing the star field to free the
|
|
108
|
+
* underlying buffer geometry and material.
|
|
109
|
+
*
|
|
110
|
+
* @param opts - Star-field configuration (count, radius range, point size, opacity).
|
|
111
|
+
* All properties are optional and have sensible defaults.
|
|
112
|
+
* @param THREE - The Three.js module, passed at runtime to avoid a hard dependency
|
|
113
|
+
* on `three` in the library bundle.
|
|
114
|
+
* @returns A `THREE.Points` object ready to be added to the scene.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import * as THREE from 'three'
|
|
119
|
+
* import { createStarField } from '@motioncomplex/cosmos-lib/three'
|
|
120
|
+
*
|
|
121
|
+
* const stars = createStarField({
|
|
122
|
+
* count: 50_000,
|
|
123
|
+
* minRadius: 30_000,
|
|
124
|
+
* maxRadius: 150_000,
|
|
125
|
+
* }, THREE)
|
|
126
|
+
*
|
|
127
|
+
* scene.add(stars)
|
|
128
|
+
* // later:
|
|
129
|
+
* scene.remove(stars)
|
|
130
|
+
* stars.userData.dispose()
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function createStarField(opts: StarFieldOptions | undefined, THREE: typeof import('three')): THREE.Points;
|
|
134
|
+
/**
|
|
135
|
+
* Create a circular orbit line lying on the XZ plane.
|
|
136
|
+
*
|
|
137
|
+
* Generates a closed circle of `segments` line segments at the given
|
|
138
|
+
* `distance` from the origin. Useful for visualising planetary orbits
|
|
139
|
+
* or other radial guides.
|
|
140
|
+
*
|
|
141
|
+
* Call `line.userData.dispose()` when removing the orbit to free the
|
|
142
|
+
* underlying buffer geometry and material.
|
|
143
|
+
*
|
|
144
|
+
* @param distance - Orbit radius in scene units.
|
|
145
|
+
* @param opts - Visual options (colour, opacity, segment count).
|
|
146
|
+
* @param THREE - The Three.js module, passed at runtime to avoid a hard
|
|
147
|
+
* dependency on `three` in the library bundle.
|
|
148
|
+
* @returns A `THREE.Line` representing the circular orbit.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import * as THREE from 'three'
|
|
153
|
+
* import { createOrbit } from '@motioncomplex/cosmos-lib/three'
|
|
154
|
+
*
|
|
155
|
+
* // Draw Earth's orbit at 150 scene units
|
|
156
|
+
* const orbit = createOrbit(150, { color: 0x4488ff, opacity: 0.3 }, THREE)
|
|
157
|
+
* scene.add(orbit)
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function createOrbit(distance: number, opts: OrbitOptions | undefined, THREE: typeof import('three')): THREE.Line;
|