@johnmorrisdotca/chikyu-earth 0.43.0 → 0.46.0
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/CHANGELOG.md +16 -0
- package/NOTICE.md +15 -5
- package/README.md +4 -4
- package/dist/door/map.js +5 -1
- package/dist/element.d.ts +30 -0
- package/dist/element.js +82 -2
- package/dist/markers/here-city-host.d.ts +3 -1
- package/dist/markers/here-city-host.js +67 -5
- package/dist/markers/here-city.d.ts +94 -1
- package/dist/markers/here-city.js +69 -1
- package/dist/markers/index.d.ts +1 -1
- package/dist/markers/index.js +1 -1
- package/dist/realistic/element-base.d.ts +37 -0
- package/dist/realistic/element-base.js +86 -14
- package/dist/realistic/index.d.ts +1 -0
- package/dist/realistic/index.js +1 -0
- package/dist/realistic/zoom-reach.d.ts +29 -0
- package/dist/realistic/zoom-reach.js +30 -0
- package/dist/satellites/catalogue.d.ts +52 -1
- package/dist/satellites/catalogue.js +96 -5
- package/dist/satellites/index.d.ts +1 -1
- package/dist/satellites/index.js +1 -1
- package/dist/satellites/track.js +18 -3
- package/dist/satellites/types.d.ts +2 -2
- package/dist/sea-names/features.d.ts +12 -0
- package/dist/sea-names/features.js +46 -0
- package/dist/sea-names/geometry.d.ts +121 -0
- package/dist/sea-names/geometry.js +135 -0
- package/dist/sea-names/host.d.ts +46 -0
- package/dist/sea-names/host.js +111 -0
- package/dist/space/element-base.d.ts +48 -1
- package/dist/space/element-base.js +109 -9
- package/dist/space/generic-satellite.d.ts +46 -0
- package/dist/space/generic-satellite.js +96 -0
- package/dist/space/index.d.ts +2 -1
- package/dist/space/index.js +2 -1
- package/dist/space/ride.d.ts +45 -0
- package/dist/space/ride.js +38 -0
- package/dist/space/satellite-layer.d.ts +37 -0
- package/dist/space/satellite-layer.js +96 -14
- package/dist/space/scene.d.ts +3 -1
- package/dist/space/scene.js +54 -25
- package/package.json +3 -3
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Names of oceans, seas and continents over an element's picture. The element tells this where the Earth is at each draw. Nothing is added until `sea-names` is on, and nothing is drawn at rest.
|
|
2
|
+
import { LAND_LETTER_SPACING, SEA_LETTER_SPACING, layoutSeaNames, readSeaNames } from "./geometry.js";
|
|
3
|
+
/** The styles of the layer (`#sea-names` in the element's shadow root). Water is spaced out; continents a little less. */
|
|
4
|
+
export const SEA_NAMES_STYLE = "#sea-names{position:absolute;inset:0;overflow:hidden;pointer-events:none}" +
|
|
5
|
+
".sea-name{position:absolute;left:0;top:0;margin:0;white-space:nowrap;text-align:center;pointer-events:none;will-change:transform;" +
|
|
6
|
+
"font-family:var(--chikyu-sea-font,system-ui,-apple-system,'Segoe UI',sans-serif);font-weight:500;color:var(--chikyu-sea-colour,rgba(186,214,228,.9));" +
|
|
7
|
+
`letter-spacing:${SEA_LETTER_SPACING}em;` +
|
|
8
|
+
"text-shadow:0 0 3px #061018,0 0 3px #061018}" +
|
|
9
|
+
`.sea-name[data-kind=continent]{letter-spacing:${LAND_LETTER_SPACING}em;color:var(--chikyu-land-colour,rgba(232,224,200,.92))}` +
|
|
10
|
+
".sea-name[hidden]{display:none}";
|
|
11
|
+
/**
|
|
12
|
+
* Makes the layer of one element. Nothing is added to the root until `sea-names` is on.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The attribute reader, the language and the shadow root.
|
|
15
|
+
* @returns The host.
|
|
16
|
+
*/
|
|
17
|
+
export function createSeaHost(options) {
|
|
18
|
+
const { root } = options;
|
|
19
|
+
const doc = root.ownerDocument;
|
|
20
|
+
let on = readSeaNames(options.attribute("sea-names"));
|
|
21
|
+
let last = null;
|
|
22
|
+
let taken = [];
|
|
23
|
+
let shown = [];
|
|
24
|
+
let renders = 0;
|
|
25
|
+
let box;
|
|
26
|
+
const pool = [];
|
|
27
|
+
const attach = () => {
|
|
28
|
+
if (box)
|
|
29
|
+
return;
|
|
30
|
+
box = doc.createElement("div");
|
|
31
|
+
box.id = "sea-names";
|
|
32
|
+
box.setAttribute("aria-hidden", "true");
|
|
33
|
+
const cities = root.getElementById("cn-canvas");
|
|
34
|
+
if (cities)
|
|
35
|
+
root.insertBefore(box, cities);
|
|
36
|
+
else
|
|
37
|
+
root.append(box);
|
|
38
|
+
};
|
|
39
|
+
const clear = () => {
|
|
40
|
+
for (const name of pool)
|
|
41
|
+
name.hidden = true;
|
|
42
|
+
shown = [];
|
|
43
|
+
};
|
|
44
|
+
const place = () => {
|
|
45
|
+
if (!box)
|
|
46
|
+
return;
|
|
47
|
+
renders += 1;
|
|
48
|
+
while (pool.length < shown.length) {
|
|
49
|
+
const name = doc.createElement("span");
|
|
50
|
+
name.className = "sea-name";
|
|
51
|
+
box.append(name);
|
|
52
|
+
pool.push(name);
|
|
53
|
+
}
|
|
54
|
+
pool.forEach((name, index) => {
|
|
55
|
+
const one = shown[index];
|
|
56
|
+
if (!one) {
|
|
57
|
+
name.hidden = true;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
name.hidden = false;
|
|
61
|
+
name.dataset["kind"] = one.kind;
|
|
62
|
+
name.textContent = one.text;
|
|
63
|
+
name.style.fontSize = `${one.size}px`;
|
|
64
|
+
name.style.transform = `translate(${one.left}px, ${one.top}px)`;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
const compute = () => {
|
|
68
|
+
if (!on || !last) {
|
|
69
|
+
clear();
|
|
70
|
+
if (box)
|
|
71
|
+
place();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
attach();
|
|
75
|
+
shown = layoutSeaNames(last.radius, last, options.language(), taken);
|
|
76
|
+
place();
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
frame(frame, next = []) {
|
|
80
|
+
last = frame;
|
|
81
|
+
taken = next;
|
|
82
|
+
compute();
|
|
83
|
+
},
|
|
84
|
+
refresh() {
|
|
85
|
+
on = readSeaNames(options.attribute("sea-names"));
|
|
86
|
+
if (!on) {
|
|
87
|
+
clear();
|
|
88
|
+
box?.remove();
|
|
89
|
+
box = undefined;
|
|
90
|
+
pool.length = 0;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
compute();
|
|
94
|
+
},
|
|
95
|
+
get shown() {
|
|
96
|
+
return shown;
|
|
97
|
+
},
|
|
98
|
+
get boxes() {
|
|
99
|
+
return shown.map((one) => ({ left: one.left, top: one.top, width: one.width, height: one.height }));
|
|
100
|
+
},
|
|
101
|
+
get stats() {
|
|
102
|
+
return { on, radius: last?.radius ?? 0, names: on ? shown.length : 0, renders };
|
|
103
|
+
},
|
|
104
|
+
dispose() {
|
|
105
|
+
clear();
|
|
106
|
+
box?.remove();
|
|
107
|
+
box = undefined;
|
|
108
|
+
on = false;
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -10,6 +10,7 @@ import type { BorderData, BorderStats } from "../borders/layer.ts";
|
|
|
10
10
|
import { type RouteLeg } from "../route.ts";
|
|
11
11
|
import type { GridStats } from "../grid/layer.ts";
|
|
12
12
|
import { type CountryNamesStats, type CountryNamesStyle } from "../country-names/host.ts";
|
|
13
|
+
import { type SeaNamesStats } from "../sea-names/host.ts";
|
|
13
14
|
import type { TileStats } from "../realistic/tile-set.ts";
|
|
14
15
|
import { setThreeLoader } from "../realistic/shared.ts";
|
|
15
16
|
import type { LightMode } from "../realistic/earth.ts";
|
|
@@ -17,7 +18,7 @@ import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/type
|
|
|
17
18
|
import { type PlanetName } from "./ephemeris.ts";
|
|
18
19
|
import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts";
|
|
19
20
|
import { type SatelliteOthers } from "./satellite-focus.ts";
|
|
20
|
-
import { type RideFace, type RideLook } from "./ride.ts";
|
|
21
|
+
import { type RideFace, type RideLook, type RideViewpoint } from "./ride.ts";
|
|
21
22
|
import { type ScaleMode } from "./scale.ts";
|
|
22
23
|
import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type SatellitePainter } from "./scene.ts";
|
|
23
24
|
import { type PaintSpec } from "../paint/buffer.ts";
|
|
@@ -113,6 +114,8 @@ export interface RideOptions {
|
|
|
113
114
|
look?: RideLook;
|
|
114
115
|
/** Face this way as the ride opens (`face`). */
|
|
115
116
|
face?: RideFace;
|
|
117
|
+
/** `outside` (the default, or the element's `ride-viewpoint`) shows the satellite: with `view: "from"` the camera is a little behind and above it (straight above it with `look: "down"`), and a satellite the page has no model for is drawn small from the package's own sketch of its kind. `inside` is the camera at the satellite, as before, and no sketch. A body is always ridden from inside. */
|
|
118
|
+
viewpoint?: RideViewpoint;
|
|
116
119
|
distanceKm?: number;
|
|
117
120
|
smooth?: boolean;
|
|
118
121
|
}
|
|
@@ -133,6 +136,8 @@ export interface Riding {
|
|
|
133
136
|
look: RideLook;
|
|
134
137
|
face: RideFace | null;
|
|
135
138
|
distanceKm: number;
|
|
139
|
+
/** `outside` or `inside` (see `RideOptions`). */
|
|
140
|
+
viewpoint: RideViewpoint;
|
|
136
141
|
}
|
|
137
142
|
type SatelliteStats = {
|
|
138
143
|
groups: number;
|
|
@@ -140,6 +145,11 @@ type SatelliteStats = {
|
|
|
140
145
|
segments: number;
|
|
141
146
|
tooFast: boolean;
|
|
142
147
|
dotScale: number;
|
|
148
|
+
longestStreakPx: number;
|
|
149
|
+
streakCapPx: number;
|
|
150
|
+
weight: number;
|
|
151
|
+
fade: number;
|
|
152
|
+
earthPx: number;
|
|
143
153
|
epochMs: number;
|
|
144
154
|
propagations: number;
|
|
145
155
|
lastBatchMs: number;
|
|
@@ -339,6 +349,21 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
339
349
|
*/
|
|
340
350
|
get countryNamesStyle(): CountryNamesStyle;
|
|
341
351
|
set countryNamesStyle(value: CountryNamesStyle);
|
|
352
|
+
/**
|
|
353
|
+
* Names of oceans, seas and continents (the attribute `sea-names`). Off unless set: a bare attribute is on. Oceans and continents from far out, seas once the Earth is large on the screen. A city name keeps the space where both fit only one. Nothing is drawn again at rest.
|
|
354
|
+
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts no-run
|
|
357
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
358
|
+
*
|
|
359
|
+
* const space = document.querySelector("chikyu-space") as ChikyuSpace;
|
|
360
|
+
* space.seaNames = true;
|
|
361
|
+
* console.log(space.seaNames);
|
|
362
|
+
* space.seaNames = false;
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
get seaNames(): boolean;
|
|
366
|
+
set seaNames(value: boolean);
|
|
342
367
|
/**
|
|
343
368
|
* Which borders are drawn on the Earth (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
|
|
344
369
|
* Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
|
|
@@ -455,6 +480,12 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
455
480
|
noradId: number;
|
|
456
481
|
name: string;
|
|
457
482
|
} | null;
|
|
483
|
+
/**
|
|
484
|
+
* Where a ride puts the camera: `outside` (the default; the attribute `ride-viewpoint`) shows the satellite, `inside` puts the camera at it. It is the default for the next `ride` and, set while riding, moves the ride there in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock.
|
|
485
|
+
* See `RideOptions.viewpoint`.
|
|
486
|
+
*/
|
|
487
|
+
get rideViewpoint(): RideViewpoint;
|
|
488
|
+
set rideViewpoint(value: RideViewpoint);
|
|
458
489
|
/** What the camera is riding along with now, or null. */
|
|
459
490
|
get riding(): Riding | null;
|
|
460
491
|
/**
|
|
@@ -462,6 +493,20 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
462
493
|
*/
|
|
463
494
|
get satelliteTint(): "off" | "orbit";
|
|
464
495
|
set satelliteTint(value: "off" | "orbit");
|
|
496
|
+
/**
|
|
497
|
+
* The longest a satellite's streak may be on the screen, in CSS pixels (the attribute `satellite-streak-max`; 8 when the page says nothing; `0` or `off` for no cap). Above 60 times real time each satellite is drawn as a streak along its orbit
|
|
498
|
+
* for the stretch one frame spans, and at a fast clock that stretch is long: at an hour a second a low satellite would cross a tenth of the Earth in one frame. The cap is a length on the screen, so a low and a high satellite are drawn equally long, and the streak keeps the look it has at 10 minutes a second at any speed. It is the smaller of this number of pixels and 0.025 of the Earth's drawn radius (about 160 km of orbit, what a low satellite covers in a frame at 10 minutes a second), so as the Earth is drawn smaller the streak shrinks in proportion, to a dot, instead of staying as long on a small Earth as on a large one. The marks also lose weight on a small Earth: below a drawn radius of 150 pixels the streaks are fainter and the dark rim of the dots fades, gone at 40 pixels, and a crowd of satellites on a small Earth is drawn fainter in proportion so thousands of them do not wash it. Pointing along the orbit and ending at the satellite, it is the same length at any frame rate. Off restores the whole stretch.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```ts
|
|
502
|
+
* import "@johnmorrisdotca/chikyu-earth/space/element";
|
|
503
|
+
*
|
|
504
|
+
* const space = document.querySelector("chikyu-space")!;
|
|
505
|
+
* space.satelliteStreakMax = 12;
|
|
506
|
+
* ```
|
|
507
|
+
*/
|
|
508
|
+
get satelliteStreakMax(): number;
|
|
509
|
+
set satelliteStreakMax(value: number);
|
|
465
510
|
/**
|
|
466
511
|
* Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds. Giving the name of a group
|
|
467
512
|
* that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations).
|
|
@@ -689,6 +734,8 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
689
734
|
};
|
|
690
735
|
/** The names of countries: whether `country-names` is set and the most it asks for, the countries loaded, the names shown at the last draw, how many times they were laid out, and whether the outlines could not be loaded. */
|
|
691
736
|
countryNames: CountryNamesStats;
|
|
737
|
+
/** The names of oceans, seas and continents: whether `sea-names` is on, the Earth's radius on the screen, the names shown at the last draw, and how many times the layer was laid out. */
|
|
738
|
+
seaNames: SeaNamesStats;
|
|
692
739
|
};
|
|
693
740
|
}
|
|
694
741
|
declare global {
|
|
@@ -17,6 +17,8 @@ import { readRoute, routeLeg, routeText } from "../route.js";
|
|
|
17
17
|
import { applyRoute } from "../route/layer.js";
|
|
18
18
|
import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
|
|
19
19
|
import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
|
|
20
|
+
import { SEA_NAMES_ATTRIBUTES, readSeaNames } from "../sea-names/geometry.js";
|
|
21
|
+
import { SEA_NAMES_STYLE, createSeaHost } from "../sea-names/host.js";
|
|
20
22
|
import { createGate, frameCap } from "../realistic/gate.js";
|
|
21
23
|
import { folderSource } from "../door/map.js";
|
|
22
24
|
import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
|
|
@@ -26,7 +28,7 @@ import { readMeteorStrength } from "../meteors/strength.js";
|
|
|
26
28
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
27
29
|
import { MAX_TEXTURE } from "../realistic/tiers.js";
|
|
28
30
|
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
|
|
29
|
-
import { MAX_ORBIT_GROUP } from "./satellite-layer.js";
|
|
31
|
+
import { MAX_ORBIT_GROUP, readStreakMax } from "./satellite-layer.js";
|
|
30
32
|
import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForPerspectiveShell } from "./satellite-focus.js";
|
|
31
33
|
import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
32
34
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
@@ -112,7 +114,7 @@ const readTime = (value) => {
|
|
|
112
114
|
const ms = Date.parse(value);
|
|
113
115
|
return Number.isFinite(ms) ? ms : "now";
|
|
114
116
|
};
|
|
115
|
-
const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
|
|
117
|
+
const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
|
|
116
118
|
/**
|
|
117
119
|
* The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
|
|
118
120
|
*
|
|
@@ -154,7 +156,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
154
156
|
* ```
|
|
155
157
|
*/
|
|
156
158
|
export class ChikyuSpace extends HTMLElement {
|
|
157
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "tiles"];
|
|
159
|
+
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "ride-viewpoint"];
|
|
158
160
|
#model = newSpaceModel();
|
|
159
161
|
#paint = createPaintState();
|
|
160
162
|
#mode = "now";
|
|
@@ -172,6 +174,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
172
174
|
#citiesStyle = {};
|
|
173
175
|
/** The names of the countries on the Earth (`country-names`), and the look of the names. */
|
|
174
176
|
#countries;
|
|
177
|
+
#seas;
|
|
175
178
|
#countriesStyle = {};
|
|
176
179
|
#satNames = {};
|
|
177
180
|
/** A ringed satellite's name, by `group:index`, for `#satLabelLang`. The name does not depend on the moment, so a frame reads it and does not propagate the orbit again. */
|
|
@@ -283,6 +286,11 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
283
286
|
onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
|
|
284
287
|
});
|
|
285
288
|
this.#countries.setStyle(this.#countriesStyle);
|
|
289
|
+
this.#seas = createSeaHost({
|
|
290
|
+
root,
|
|
291
|
+
attribute: (name) => this.getAttribute(name),
|
|
292
|
+
language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
|
|
293
|
+
});
|
|
286
294
|
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
287
295
|
this.#applyBodyLabel();
|
|
288
296
|
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
@@ -390,10 +398,14 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
390
398
|
this.#cities?.dispose();
|
|
391
399
|
this.#countries?.dispose();
|
|
392
400
|
this.#countries = undefined;
|
|
401
|
+
this.#seas?.dispose();
|
|
402
|
+
this.#seas = undefined;
|
|
393
403
|
this.#cities = undefined;
|
|
394
404
|
}
|
|
395
405
|
attributeChangedCallback(name, _old, value) {
|
|
396
|
-
if (name === "
|
|
406
|
+
if (name === "ride-viewpoint")
|
|
407
|
+
this.#applyViewpoint();
|
|
408
|
+
else if (name === "center")
|
|
397
409
|
this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
|
|
398
410
|
else if (name === "time")
|
|
399
411
|
this.time = readTime(value);
|
|
@@ -437,6 +449,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
437
449
|
this.#applyBodyLabel();
|
|
438
450
|
this.#sky?.refresh();
|
|
439
451
|
this.#cities?.refresh();
|
|
452
|
+
this.#seas?.refresh();
|
|
440
453
|
this.#countries?.refresh();
|
|
441
454
|
this.#here?.refresh();
|
|
442
455
|
}
|
|
@@ -467,6 +480,11 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
467
480
|
}
|
|
468
481
|
else if (CITY_NAMES_ATTRIBUTES.includes(name))
|
|
469
482
|
this.#cities?.refresh();
|
|
483
|
+
else if (SEA_NAMES_ATTRIBUTES.includes(name)) {
|
|
484
|
+
this.#seas?.refresh();
|
|
485
|
+
this.#seaFrame();
|
|
486
|
+
this.#countryFrame();
|
|
487
|
+
}
|
|
470
488
|
else if (name === "borders") {
|
|
471
489
|
Object.assign(this.#model.borders, readBorders(value));
|
|
472
490
|
this.#gate?.request();
|
|
@@ -481,6 +499,10 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
481
499
|
this.#model.satellites.orbitTint = value === "orbit";
|
|
482
500
|
this.#gate?.request();
|
|
483
501
|
}
|
|
502
|
+
else if (name === "satellite-streak-max") {
|
|
503
|
+
this.#model.satellites.streakMax = readStreakMax(value);
|
|
504
|
+
this.#gate?.request();
|
|
505
|
+
}
|
|
484
506
|
else if (name === "tiles")
|
|
485
507
|
this.#gate?.request();
|
|
486
508
|
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
@@ -823,6 +845,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
823
845
|
#relayNames(cities, sky) {
|
|
824
846
|
if (cities)
|
|
825
847
|
this.#cities?.frame(this.#lastNameFrame, this.#boxesBeforeCities());
|
|
848
|
+
this.#seaFrame();
|
|
826
849
|
this.#countryFrame();
|
|
827
850
|
if (sky)
|
|
828
851
|
this.#sky?.relayout();
|
|
@@ -842,18 +865,26 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
842
865
|
out.length = 0;
|
|
843
866
|
if (!this.#lastNameFrame)
|
|
844
867
|
return out;
|
|
845
|
-
out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []));
|
|
868
|
+
out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? []));
|
|
846
869
|
return out;
|
|
847
870
|
}
|
|
848
871
|
/** The frame the names were last laid out on. */
|
|
849
872
|
#lastNameFrame = null;
|
|
850
|
-
/** Lays the
|
|
873
|
+
/** Lays the ocean, sea and continent names out on the last frame, clear of the bodies', the places' and the cities'. A city placed first keeps the space. */
|
|
874
|
+
#seaFrame() {
|
|
875
|
+
const seas = this.#seas;
|
|
876
|
+
if (!seas)
|
|
877
|
+
return;
|
|
878
|
+
const frame = this.#lastNameFrame;
|
|
879
|
+
seas.frame(frame, seas.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
|
|
880
|
+
}
|
|
881
|
+
/** Lays the countries' names out on the last frame, clear of the bodies', the places', the cities' and the sea names as they are now. */
|
|
851
882
|
#countryFrame() {
|
|
852
883
|
const countries = this.#countries;
|
|
853
884
|
if (!countries)
|
|
854
885
|
return;
|
|
855
886
|
const frame = this.#lastNameFrame;
|
|
856
|
-
countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
|
|
887
|
+
countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? [])] : []);
|
|
857
888
|
}
|
|
858
889
|
/** The boxes the bodies' names take beside them in the picture just drawn. */
|
|
859
890
|
#bodyNameBoxes() {
|
|
@@ -908,6 +939,28 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
908
939
|
this.#countriesStyle = { ...value };
|
|
909
940
|
this.#countries?.setStyle(this.#countriesStyle);
|
|
910
941
|
}
|
|
942
|
+
/**
|
|
943
|
+
* Names of oceans, seas and continents (the attribute `sea-names`). Off unless set: a bare attribute is on. Oceans and continents from far out, seas once the Earth is large on the screen. A city name keeps the space where both fit only one. Nothing is drawn again at rest.
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
* ```ts no-run
|
|
947
|
+
* import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
|
|
948
|
+
*
|
|
949
|
+
* const space = document.querySelector("chikyu-space") as ChikyuSpace;
|
|
950
|
+
* space.seaNames = true;
|
|
951
|
+
* console.log(space.seaNames);
|
|
952
|
+
* space.seaNames = false;
|
|
953
|
+
* ```
|
|
954
|
+
*/
|
|
955
|
+
get seaNames() {
|
|
956
|
+
return readSeaNames(this.getAttribute("sea-names"));
|
|
957
|
+
}
|
|
958
|
+
set seaNames(value) {
|
|
959
|
+
if (value)
|
|
960
|
+
this.setAttribute("sea-names", "");
|
|
961
|
+
else
|
|
962
|
+
this.removeAttribute("sea-names");
|
|
963
|
+
}
|
|
911
964
|
/**
|
|
912
965
|
* Which borders are drawn on the Earth (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
|
|
913
966
|
* Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
|
|
@@ -1164,7 +1217,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1164
1217
|
// a body followed (a planet, the Moon, the Earth) is looked at from round it as the view turns: it has no ways to face
|
|
1165
1218
|
const faceable = !(view === "follow" && typeof target === "string");
|
|
1166
1219
|
const face = faceable && options.face && RIDE_FACES.includes(options.face) ? options.face : null;
|
|
1167
|
-
model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000) };
|
|
1220
|
+
model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000), viewpoint: options.viewpoint === "inside" || options.viewpoint === "outside" ? options.viewpoint : this.rideViewpoint };
|
|
1168
1221
|
if (face) {
|
|
1169
1222
|
model.view = { yaw: 0, tilt: 0, zoom: model.view.zoom };
|
|
1170
1223
|
model.rideTurn = 0;
|
|
@@ -1297,6 +1350,31 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1297
1350
|
this.ride(next.ref, { view: "follow" });
|
|
1298
1351
|
return next;
|
|
1299
1352
|
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Where a ride puts the camera: `outside` (the default; the attribute `ride-viewpoint`) shows the satellite, `inside` puts the camera at it. It is the default for the next `ride` and, set while riding, moves the ride there in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock.
|
|
1355
|
+
* See `RideOptions.viewpoint`.
|
|
1356
|
+
*/
|
|
1357
|
+
get rideViewpoint() {
|
|
1358
|
+
return this.getAttribute("ride-viewpoint") === "inside" ? "inside" : "outside";
|
|
1359
|
+
}
|
|
1360
|
+
set rideViewpoint(value) {
|
|
1361
|
+
this.setAttribute("ride-viewpoint", value === "inside" ? "inside" : "outside");
|
|
1362
|
+
}
|
|
1363
|
+
#applyViewpoint() {
|
|
1364
|
+
const model = this.#model;
|
|
1365
|
+
const ride = model.ride;
|
|
1366
|
+
const next = this.rideViewpoint;
|
|
1367
|
+
if (!ride || ride.viewpoint === next)
|
|
1368
|
+
return;
|
|
1369
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1370
|
+
const pose = model.pose;
|
|
1371
|
+
model.ride = { ...ride, viewpoint: next };
|
|
1372
|
+
model.transition = !reduced && pose.valid ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
|
|
1373
|
+
this.#last = performance.now();
|
|
1374
|
+
this.#schedule();
|
|
1375
|
+
this.#gate?.request();
|
|
1376
|
+
this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
|
|
1377
|
+
}
|
|
1300
1378
|
/** What the camera is riding along with now, or null. */
|
|
1301
1379
|
get riding() {
|
|
1302
1380
|
const ride = this.#model.ride;
|
|
@@ -1321,6 +1399,27 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1321
1399
|
else
|
|
1322
1400
|
this.removeAttribute("satellite-tint");
|
|
1323
1401
|
}
|
|
1402
|
+
/**
|
|
1403
|
+
* The longest a satellite's streak may be on the screen, in CSS pixels (the attribute `satellite-streak-max`; 8 when the page says nothing; `0` or `off` for no cap). Above 60 times real time each satellite is drawn as a streak along its orbit
|
|
1404
|
+
* for the stretch one frame spans, and at a fast clock that stretch is long: at an hour a second a low satellite would cross a tenth of the Earth in one frame. The cap is a length on the screen, so a low and a high satellite are drawn equally long, and the streak keeps the look it has at 10 minutes a second at any speed. It is the smaller of this number of pixels and 0.025 of the Earth's drawn radius (about 160 km of orbit, what a low satellite covers in a frame at 10 minutes a second), so as the Earth is drawn smaller the streak shrinks in proportion, to a dot, instead of staying as long on a small Earth as on a large one. The marks also lose weight on a small Earth: below a drawn radius of 150 pixels the streaks are fainter and the dark rim of the dots fades, gone at 40 pixels, and a crowd of satellites on a small Earth is drawn fainter in proportion so thousands of them do not wash it. Pointing along the orbit and ending at the satellite, it is the same length at any frame rate. Off restores the whole stretch.
|
|
1405
|
+
*
|
|
1406
|
+
* @example
|
|
1407
|
+
* ```ts
|
|
1408
|
+
* import "@johnmorrisdotca/chikyu-earth/space/element";
|
|
1409
|
+
*
|
|
1410
|
+
* const space = document.querySelector("chikyu-space")!;
|
|
1411
|
+
* space.satelliteStreakMax = 12;
|
|
1412
|
+
* ```
|
|
1413
|
+
*/
|
|
1414
|
+
get satelliteStreakMax() {
|
|
1415
|
+
return this.#model.satellites.streakMax;
|
|
1416
|
+
}
|
|
1417
|
+
set satelliteStreakMax(value) {
|
|
1418
|
+
if (Number.isFinite(value) && value >= 0)
|
|
1419
|
+
this.setAttribute("satellite-streak-max", String(value));
|
|
1420
|
+
else
|
|
1421
|
+
this.removeAttribute("satellite-streak-max");
|
|
1422
|
+
}
|
|
1324
1423
|
/**
|
|
1325
1424
|
* Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds. Giving the name of a group
|
|
1326
1425
|
* that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations).
|
|
@@ -1633,6 +1732,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1633
1732
|
grid: { ...this.#model.grid.stats },
|
|
1634
1733
|
route: { ...this.#model.route.stats },
|
|
1635
1734
|
countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
|
|
1735
|
+
seaNames: this.#seas?.stats ?? { on: false, radius: 0, names: 0, renders: 0 },
|
|
1636
1736
|
};
|
|
1637
1737
|
}
|
|
1638
1738
|
#satelliteStats() {
|
|
@@ -1648,7 +1748,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
1648
1748
|
let epochMs = 0;
|
|
1649
1749
|
for (const group of this.#model.satellites.groups.values())
|
|
1650
1750
|
epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
|
|
1651
|
-
return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates };
|
|
1751
|
+
return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, longestStreakPx: drawn.longestStreakPx, streakCapPx: drawn.streakCapPx, weight: drawn.weight, fade: drawn.fade, earthPx: drawn.earthPx, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates };
|
|
1652
1752
|
}
|
|
1653
1753
|
// --- the game clock ----------------------------------------------------------------------------------------------------------------------------
|
|
1654
1754
|
#readSpeed() {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type * as THREE from "three";
|
|
2
|
+
import type { BodyDrawing } from "./scene.ts";
|
|
3
|
+
/**
|
|
4
|
+
* What a generic drawing shows: `bus` a box with two solar panels, `communications` the same with a dish on its nadir face, `flat` a flat panel with one long solar array (the shape of a large constellation's satellites), `station` a row of modules with a truss and panels.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import type { SatelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
|
|
9
|
+
*
|
|
10
|
+
* const kinds: SatelliteKind[] = ["bus", "communications", "flat", "station"];
|
|
11
|
+
* console.log(kinds.length);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type SatelliteKind = "bus" | "communications" | "flat" | "station";
|
|
15
|
+
/**
|
|
16
|
+
* Which kind of drawing a satellite gets, from its name: a large constellation (`STARLINK`, `ONEWEB`, `KUIPER`) is `flat`, a station (`ISS`, `ZARYA`, `TIANGONG`, `CSS`) is `station`, a communications satellite (by the common operators' names) has a dish, and anything else is a plain `bus`.
|
|
17
|
+
*
|
|
18
|
+
* @param name - The satellite's name (the element set's `OBJECT_NAME`).
|
|
19
|
+
* @returns The kind.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { satelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
|
|
24
|
+
*
|
|
25
|
+
* console.log(satelliteKind("STARLINK-1007"), satelliteKind("ISS (ZARYA)"), satelliteKind("INTELSAT 39"), satelliteKind("NOAA 19"));
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function satelliteKind(name: string): SatelliteKind;
|
|
29
|
+
/**
|
|
30
|
+
* A generic satellite as a drawing of radius 1 about the origin, its long axis along +x (the way it flies), its top along +z and its left along +y, the family's convention for a model, with its own light that `light(toSun)` turns to the Sun. One group of a few meshes, made once and disposed with `dispose`.
|
|
31
|
+
*
|
|
32
|
+
* @param three - three.js (the parts the demo's subset holds: `Group`, `Mesh`, `BoxGeometry`, `CylinderGeometry`, `MeshLambertMaterial`, `DirectionalLight`, `AmbientLight`).
|
|
33
|
+
* @param kind - What to draw.
|
|
34
|
+
* @returns The drawing, with `light` and `dispose`.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts no-run
|
|
38
|
+
* import { genericSatellite } from "@johnmorrisdotca/chikyu-earth/space";
|
|
39
|
+
*
|
|
40
|
+
* const three = await import("three");
|
|
41
|
+
* const drawing = genericSatellite(three, "communications");
|
|
42
|
+
* console.log(drawing.object.children.length);
|
|
43
|
+
* drawing.dispose();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function genericSatellite(three: typeof THREE, kind: SatelliteKind): BodyDrawing;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const COMMS = /(INTELSAT|SES-|EUTELSAT|ASTRA|ECHOSTAR|DIRECTV|TELSTAR|GALAXY|YAMAL|THURAYA|INMARSAT|IRIDIUM|GLOBALSTAR|ORBCOMM|TDRS|VIASAT|ANIK|SKYNET|MILSTAR|SAT-|SATCOM|COMSAT|OPTUS|JCSAT|SUPERBIRD|HISPASAT|ARABSAT|NILESAT|TURKSAT|KOREASAT|ASIASAT|APSTAR|EXPRESS|BADR)/i;
|
|
2
|
+
/**
|
|
3
|
+
* Which kind of drawing a satellite gets, from its name: a large constellation (`STARLINK`, `ONEWEB`, `KUIPER`) is `flat`, a station (`ISS`, `ZARYA`, `TIANGONG`, `CSS`) is `station`, a communications satellite (by the common operators' names) has a dish, and anything else is a plain `bus`.
|
|
4
|
+
*
|
|
5
|
+
* @param name - The satellite's name (the element set's `OBJECT_NAME`).
|
|
6
|
+
* @returns The kind.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { satelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
|
|
11
|
+
*
|
|
12
|
+
* console.log(satelliteKind("STARLINK-1007"), satelliteKind("ISS (ZARYA)"), satelliteKind("INTELSAT 39"), satelliteKind("NOAA 19"));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function satelliteKind(name) {
|
|
16
|
+
if (/^(STARLINK|ONEWEB|KUIPER)/i.test(name))
|
|
17
|
+
return "flat";
|
|
18
|
+
if (/(ISS|ZARYA|TIANGONG|CSS|TIANHE|WENTIAN|MENGTIAN)/i.test(name))
|
|
19
|
+
return "station";
|
|
20
|
+
if (COMMS.test(name))
|
|
21
|
+
return "communications";
|
|
22
|
+
return "bus";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A generic satellite as a drawing of radius 1 about the origin, its long axis along +x (the way it flies), its top along +z and its left along +y, the family's convention for a model, with its own light that `light(toSun)` turns to the Sun. One group of a few meshes, made once and disposed with `dispose`.
|
|
26
|
+
*
|
|
27
|
+
* @param three - three.js (the parts the demo's subset holds: `Group`, `Mesh`, `BoxGeometry`, `CylinderGeometry`, `MeshLambertMaterial`, `DirectionalLight`, `AmbientLight`).
|
|
28
|
+
* @param kind - What to draw.
|
|
29
|
+
* @returns The drawing, with `light` and `dispose`.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts no-run
|
|
33
|
+
* import { genericSatellite } from "@johnmorrisdotca/chikyu-earth/space";
|
|
34
|
+
*
|
|
35
|
+
* const three = await import("three");
|
|
36
|
+
* const drawing = genericSatellite(three, "communications");
|
|
37
|
+
* console.log(drawing.object.children.length);
|
|
38
|
+
* drawing.dispose();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function genericSatellite(three, kind) {
|
|
42
|
+
const group = new three.Group();
|
|
43
|
+
const materials = [];
|
|
44
|
+
const geometries = [];
|
|
45
|
+
const half = Math.PI / 2;
|
|
46
|
+
const add = (geometry, colour, at, spin = [0, 0, 0]) => {
|
|
47
|
+
const material = new three.MeshLambertMaterial({ color: colour });
|
|
48
|
+
const mesh = new three.Mesh(geometry, material);
|
|
49
|
+
mesh.position.set(at[0], at[1], at[2]);
|
|
50
|
+
mesh.rotation.set(spin[0], spin[1], spin[2]);
|
|
51
|
+
group.add(mesh);
|
|
52
|
+
materials.push(material);
|
|
53
|
+
geometries.push(geometry);
|
|
54
|
+
};
|
|
55
|
+
const box = (x, y, z) => new three.BoxGeometry(x, y, z);
|
|
56
|
+
const tube = (radius, length) => new three.CylinderGeometry(radius, radius, length, 16);
|
|
57
|
+
if (kind === "flat") {
|
|
58
|
+
add(box(0.5, 0.36, 0.03), 0xd7dadf, [0, 0, 0]);
|
|
59
|
+
add(box(0.5, 1.1, 0.01), 0x1f3f7a, [0, 0.74, 0]);
|
|
60
|
+
}
|
|
61
|
+
else if (kind === "station") {
|
|
62
|
+
add(tube(0.07, 0.8), 0xd9dde3, [0, 0, 0], [0, 0, half]);
|
|
63
|
+
add(box(0.05, 1.7, 0.05), 0xb7bcc4, [-0.2, 0, 0]);
|
|
64
|
+
for (const y of [-0.75, 0.75])
|
|
65
|
+
add(box(0.3, 0.3, 0.012), 0x274a8c, [-0.2, y, 0]);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
add(box(0.5, 0.4, 0.4), 0xd7b35a, [0, 0, 0]);
|
|
69
|
+
for (const y of [-1, 1]) {
|
|
70
|
+
add(box(0.18, 0.04, 0.04), 0xb7bcc4, [0, y * 0.4, 0]);
|
|
71
|
+
add(box(0.36, 0.52, 0.012), 0x1f3f7a, [0, y * 0.72, 0]);
|
|
72
|
+
}
|
|
73
|
+
if (kind === "communications") {
|
|
74
|
+
add(tube(0.05, 0.14), 0xb7bcc4, [0.1, 0, 0.27]);
|
|
75
|
+
add(new three.CylinderGeometry(0.2, 0.02, 0.1, 20), 0xe8eaee, [0.1, 0, 0.36]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const sun = new three.DirectionalLight(0xfff4e0, 3.2);
|
|
79
|
+
group.add(sun, new three.AmbientLight(0x6f86a8, 0.9));
|
|
80
|
+
return {
|
|
81
|
+
object: group,
|
|
82
|
+
light(toSun) {
|
|
83
|
+
// the model's axes are the columns of the matrix the view set: the direction to the Sun in them is the dot with each
|
|
84
|
+
const m = group.matrix.elements;
|
|
85
|
+
const length = Math.hypot(m[0], m[1], m[2]) || 1;
|
|
86
|
+
sun.position.set((m[0] * toSun[0] + m[1] * toSun[1] + m[2] * toSun[2]) / length, (m[4] * toSun[0] + m[5] * toSun[1] + m[6] * toSun[2]) / length, (m[8] * toSun[0] + m[9] * toSun[1] + m[10] * toSun[2]) / length);
|
|
87
|
+
},
|
|
88
|
+
dispose() {
|
|
89
|
+
for (const material of materials)
|
|
90
|
+
material.dispose();
|
|
91
|
+
for (const geometry of geometries)
|
|
92
|
+
geometry.dispose();
|
|
93
|
+
sun.dispose?.();
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
package/dist/space/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
|
|
2
2
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
3
|
export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
|
|
4
|
-
export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
4
|
+
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose, type RideViewpoint } from "./ride.ts";
|
|
5
5
|
export type { SatelliteScreen } from "./satellite-layer.ts";
|
|
6
6
|
export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
|
|
7
|
+
export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-satellite.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS } from "./ephemeris.js";
|
|
4
4
|
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
5
5
|
export { fitDistance, plainPainter } from "./scene.js";
|
|
6
|
-
export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
6
|
+
export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
|
|
7
7
|
export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
|
|
8
|
+
export { genericSatellite, satelliteKind } from "./generic-satellite.js";
|