@johnmorrisdotca/chikyu-earth 0.37.0 → 0.38.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.
@@ -17,6 +17,7 @@ import { type SatelliteStyle } from "./satellite-layer.ts";
17
17
  import { type RideFace, type RideLook } from "./ride.ts";
18
18
  import { type ScaleMode } from "./scale.ts";
19
19
  import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type SatellitePainter } from "./scene.ts";
20
+ import { type PaintSpec } from "../paint/buffer.ts";
20
21
  export { BODY_NAMES, type BodyName, type CameraMode, type RideTarget };
21
22
  /**
22
23
  * Change how the Sun and the planets are drawn (before the first element connects): the space view keeps their places, sizes, light, names and orbits and asks
@@ -170,6 +171,9 @@ type SatelliteStats = {
170
171
  * const space = document.createElement("chikyu-space") as ChikyuSpace;
171
172
  * space.setAttribute("time", "2026-11-02T12:00Z");
172
173
  * space.setAttribute("speed", "86400");
174
+ * space.placeGroups = false; // place-groups="off": every place keeps its own ring
175
+ * space.paint = { id: "25544", length: "1w", swath: "coverage" };
176
+ * space.clearPaint();
173
177
  * space.addEventListener("chikyu-timechange", (event) => {
174
178
  * const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
175
179
  * console.log(new Date(time).toISOString(), running ? "running" : "held");
@@ -260,6 +264,17 @@ export declare class ChikyuSpace extends HTMLElement {
260
264
  }): Promise<Place | undefined>;
261
265
  /**
262
266
  * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
267
+ *
268
+ * @example
269
+ * ```ts no-run
270
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
271
+ *
272
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
273
+ * space.placeGroups = false;
274
+ * space.getAttribute("place-groups"); // "off"
275
+ * space.placeGroups = true;
276
+ * space.hasAttribute("place-groups"); // false
277
+ * ```
263
278
  */
264
279
  get placeGroups(): boolean;
265
280
  set placeGroups(value: boolean);
@@ -412,6 +427,15 @@ export declare class ChikyuSpace extends HTMLElement {
412
427
  * @param satellites - The group, or `null` to remove it.
413
428
  * @param style - How to draw it.
414
429
  */
430
+ /**
431
+ * Paint one satellite's path on the Earth. `id` is a NORAD catalogue number or `group:index`. `length` is how long the trail is kept, in simulated time (`1d` when left out, or `1w`, `1m`). `swath` is `track` (the point under the satellite, the default) or `coverage` (where it is at least 10° above the horizon). Setting another satellite clears the trail. `null` clears it.
432
+ */
433
+ get paint(): PaintSpec | null;
434
+ set paint(value: PaintSpec | null);
435
+ /** Take the painted trail off the Earth. */
436
+ clearPaint(): void;
437
+ /** Texels the trail has painted. 0 after `clearPaint`, and again when the painted satellite changes. */
438
+ get paintPixels(): number;
415
439
  setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
416
440
  /** Show or hide a group without losing it. */
417
441
  showSatellites(group: string, on: boolean): void;
@@ -548,7 +572,7 @@ export declare class ChikyuSpace extends HTMLElement {
548
572
  } | null;
549
573
  /**
550
574
  * The places: how many were handed over, how many are in sight at the last draw (`shown`, those gathered into groups included), how many stand up as markers of their own (`marks`) and are named (`labels`),
551
- * how many rings the one draw call draws (`sprites`) and how many of those are groups (`groups`), the satellites ringed and named, and how many times they were laid out.
575
+ * how many rings the one draw call draws (`sprites`; 0 when the picture cannot draw them), how many circles the page draws instead (`dots`) and how many of the rings are groups (`groups`), the satellites ringed and named, and how many times they were laid out.
552
576
  */
553
577
  places: {
554
578
  places: number;
@@ -560,6 +584,7 @@ export declare class ChikyuSpace extends HTMLElement {
560
584
  marks: number;
561
585
  groups: number;
562
586
  sprites: number;
587
+ dots: number;
563
588
  omitted: number;
564
589
  };
565
590
  /** The names of cities: whether `city-names` is set and the most it asks for, the Earth's radius on the screen, the tiers of kuni's cities that have arrived and how many cities, the names shown at the last draw and how many times the layer was drawn. */
@@ -4,7 +4,7 @@ import { airFor, readAirThickness } from "../realistic/air.js";
4
4
  import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
5
5
  import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
6
6
  import { cleanPlaces, readPlaceGroups, readPlaces } from "../markers/places.js";
7
- import { createPlaceLayer, PLACE_STYLE, readPlaceLook } from "../markers/place-layer.js";
7
+ import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
8
8
  import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
9
9
  import { subsolarPoint } from "../realistic/sun.js";
10
10
  import { SHORT_NAMES } from "../satellites/names.js";
@@ -25,6 +25,7 @@ import { MAX_ORBIT_GROUP } from "./satellite-layer.js";
25
25
  import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
26
26
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
27
27
  import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
28
+ import { createPaintState, paintedGround } from "../paint/buffer.js";
28
29
  export { BODY_NAMES };
29
30
  let painter;
30
31
  let satellitePainter;
@@ -131,6 +132,9 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
131
132
  * const space = document.createElement("chikyu-space") as ChikyuSpace;
132
133
  * space.setAttribute("time", "2026-11-02T12:00Z");
133
134
  * space.setAttribute("speed", "86400");
135
+ * space.placeGroups = false; // place-groups="off": every place keeps its own ring
136
+ * space.paint = { id: "25544", length: "1w", swath: "coverage" };
137
+ * space.clearPaint();
134
138
  * space.addEventListener("chikyu-timechange", (event) => {
135
139
  * const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
136
140
  * console.log(new Date(time).toISOString(), running ? "running" : "held");
@@ -141,6 +145,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
141
145
  export class ChikyuSpace extends HTMLElement {
142
146
  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", "bodies-credit", "satellite-tint"];
143
147
  #model = newSpaceModel();
148
+ #paint = createPaintState();
144
149
  #mode = "now";
145
150
  #speed = 1;
146
151
  #view;
@@ -186,6 +191,8 @@ export class ChikyuSpace extends HTMLElement {
186
191
  #ridden = {};
187
192
  #toldFacing = null;
188
193
  #placeLayer;
194
+ /** Whether the page has been told that places in sight were left undrawn. */
195
+ #placesLost = { told: false };
189
196
  #placeList = [];
190
197
  /** Counts the turns to a place, so a new one stops the one before. */
191
198
  #placeGlide = 0;
@@ -301,6 +308,14 @@ export class ChikyuSpace extends HTMLElement {
301
308
  onRideLost: () => this.#rideLost(),
302
309
  onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
303
310
  onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
311
+ paint: {
312
+ data: this.#paint.data,
313
+ width: this.#paint.width,
314
+ height: this.#paint.height,
315
+ step: (ms) => this.#paint.step(ms, (at) => paintedGround(this.#model.satellites.groups, this.#paint.id, at)),
316
+ span: () => this.#paint.spanMinutes,
317
+ on: () => this.#paint.on,
318
+ },
304
319
  ...(painter ? { painter } : {}),
305
320
  satellitePainter: () => satellitePainter,
306
321
  onPainterError: (error) => this.dispatchEvent(new CustomEvent("chikyu-bodies-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
@@ -609,6 +624,17 @@ export class ChikyuSpace extends HTMLElement {
609
624
  }
610
625
  /**
611
626
  * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
627
+ *
628
+ * @example
629
+ * ```ts no-run
630
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
631
+ *
632
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
633
+ * space.placeGroups = false;
634
+ * space.getAttribute("place-groups"); // "off"
635
+ * space.placeGroups = true;
636
+ * space.hasAttribute("place-groups"); // false
637
+ * ```
612
638
  */
613
639
  get placeGroups() {
614
640
  return this.#placeLayer?.grouping ?? readPlaceGroups(this.getAttribute("place-groups"));
@@ -619,15 +645,20 @@ export class ChikyuSpace extends HTMLElement {
619
645
  else
620
646
  this.setAttribute("place-groups", "off");
621
647
  }
622
- /** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself and the page is told once, so no place is lost without a word. */
648
+ /** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself. */
623
649
  #ringsDrawn(drawn) {
624
650
  if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
625
651
  return;
626
652
  this.#placeLayer.ringsInPicture = drawn;
627
- if (!drawn)
628
- this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: { reason: "the three.js parts handed over lack Points: the places' rings are drawn as small circles in the page, at most 600, and stats.places.omitted counts the rest" } }));
629
653
  this.#gate?.request();
630
654
  }
655
+ /** Tell the page once when places in sight had no room among the fallback circles. Missing `Points` alone leaves them drawn, so it says nothing. */
656
+ #notePlacesLost() {
657
+ const notice = placesLostNotice(this.#placesLost, this.#placeLayer?.stats.omitted ?? 0);
658
+ if (!notice)
659
+ return;
660
+ this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: notice }));
661
+ }
631
662
  /** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
632
663
  get placesLook() {
633
664
  return this.#placeLayer?.look ?? readPlaceLook(this.getAttribute("places-look"));
@@ -641,6 +672,7 @@ export class ChikyuSpace extends HTMLElement {
641
672
  if (!layer || (this.#placeList.length === 0 && this.#marks.length === 0 && layer.stats.shown === 0 && layer.stats.rings === 0))
642
673
  return;
643
674
  layer.frame(view, this.#bodyNameBoxes(), this.#marks, this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
675
+ this.#notePlacesLost();
644
676
  }
645
677
  /** Tells the names of cities, then of countries, where the Earth is in the picture just drawn; the countries' names keep clear of the bodies', the places' and the cities'. */
646
678
  #nameFrame(frame) {
@@ -1133,6 +1165,25 @@ export class ChikyuSpace extends HTMLElement {
1133
1165
  * @param satellites - The group, or `null` to remove it.
1134
1166
  * @param style - How to draw it.
1135
1167
  */
1168
+ /**
1169
+ * Paint one satellite's path on the Earth. `id` is a NORAD catalogue number or `group:index`. `length` is how long the trail is kept, in simulated time (`1d` when left out, or `1w`, `1m`). `swath` is `track` (the point under the satellite, the default) or `coverage` (where it is at least 10° above the horizon). Setting another satellite clears the trail. `null` clears it.
1170
+ */
1171
+ get paint() {
1172
+ return this.#paint.on ? { id: this.#paint.id, length: this.#paint.length, swath: this.#paint.swath } : null;
1173
+ }
1174
+ set paint(value) {
1175
+ this.#paint.set(value);
1176
+ this.#gate?.request();
1177
+ }
1178
+ /** Take the painted trail off the Earth. */
1179
+ clearPaint() {
1180
+ this.#paint.clear();
1181
+ this.#gate?.request();
1182
+ }
1183
+ /** Texels the trail has painted. 0 after `clearPaint`, and again when the painted satellite changes. */
1184
+ get paintPixels() {
1185
+ return this.#paint.pixels;
1186
+ }
1136
1187
  setSatellites(group, satellites, style = {}) {
1137
1188
  const groups = this.#model.satellites.groups;
1138
1189
  if (satellites === null) {
@@ -1337,7 +1388,7 @@ export class ChikyuSpace extends HTMLElement {
1337
1388
  bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
1338
1389
  sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
1339
1390
  followModel: this.#model.followModel,
1340
- places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, omitted: 0 }) },
1391
+ places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
1341
1392
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
1342
1393
  borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
1343
1394
  grid: { ...this.#model.grid.stats },
@@ -35,6 +35,30 @@ export interface SatelliteState {
35
35
  export declare const newSatelliteState: () => SatelliteState;
36
36
  /** The most orbits a group may draw all at once, one line each. */
37
37
  export declare const MAX_ORBIT_GROUP = 40;
38
+ /** How long, in milliseconds of wall time, a satellite's place is kept before SGP4 places it again when the clock is too fast to interpolate: about once a second. */
39
+ export declare const PIN_PERIOD_MS = 1000;
40
+ /**
41
+ * How many satellites of a group to pin in a frame that comes `elapsedMs` after the last one, so that each is pinned again about once every {@link PIN_PERIOD_MS} and no frame that comes at a lively pace pins them all: a share of the group in
42
+ * proportion to the time since the last frame (a 60 Hz frame pins about a sixtieth, a 30 Hz one a thirtieth), at least one. A frame that comes a second or more after the last one pins the whole group, as one always did: a picture that
43
+ * is drawn that seldom has no frames for a single batch to hitch.
44
+ *
45
+ * @param count - How many satellites the group has.
46
+ * @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
47
+ * @returns How many to pin now, from 0 (an empty group) to `count`. Internal: not exported from the package.
48
+ */
49
+ export declare const pinSliceSize: (count: number, elapsedMs: number) => number;
50
+ /**
51
+ * The slice of a group to pin in this frame: up to two runs of satellites as `[first, count]` (the second when the slice reaches the end and goes on from the start), and where the next slice begins.
52
+ *
53
+ * @param count - How many satellites the group has.
54
+ * @param next - Where the last slice ended (the first satellite of this one).
55
+ * @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
56
+ * @returns The runs to pin and the start of the next slice. Internal: not exported from the package.
57
+ */
58
+ export declare function pinPlan(count: number, next: number, elapsedMs: number): {
59
+ runs: [number, number][];
60
+ next: number;
61
+ };
38
62
  /**
39
63
  * Where a satellite is on the screen now: in CSS pixels in the view's box, whether it can be seen (inside the box and not behind the Earth) and how high it is.
40
64
  *
@@ -37,6 +37,37 @@ void main() {
37
37
  gl_FragColor = vec4(colour, a * (1.0 - 0.7 * vDim));
38
38
  }
39
39
  }`;
40
+ /** How long, in milliseconds of wall time, a satellite's place is kept before SGP4 places it again when the clock is too fast to interpolate: about once a second. */
41
+ export const PIN_PERIOD_MS = 1000;
42
+ /**
43
+ * How many satellites of a group to pin in a frame that comes `elapsedMs` after the last one, so that each is pinned again about once every {@link PIN_PERIOD_MS} and no frame that comes at a lively pace pins them all: a share of the group in
44
+ * proportion to the time since the last frame (a 60 Hz frame pins about a sixtieth, a 30 Hz one a thirtieth), at least one. A frame that comes a second or more after the last one pins the whole group, as one always did: a picture that
45
+ * is drawn that seldom has no frames for a single batch to hitch.
46
+ *
47
+ * @param count - How many satellites the group has.
48
+ * @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
49
+ * @returns How many to pin now, from 0 (an empty group) to `count`. Internal: not exported from the package.
50
+ */
51
+ export const pinSliceSize = (count, elapsedMs) => (count <= 0 ? 0 : Math.min(count, Math.max(1, Math.ceil((count * Math.min(PIN_PERIOD_MS, Math.max(0, elapsedMs))) / PIN_PERIOD_MS))));
52
+ /**
53
+ * The slice of a group to pin in this frame: up to two runs of satellites as `[first, count]` (the second when the slice reaches the end and goes on from the start), and where the next slice begins.
54
+ *
55
+ * @param count - How many satellites the group has.
56
+ * @param next - Where the last slice ended (the first satellite of this one).
57
+ * @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
58
+ * @returns The runs to pin and the start of the next slice. Internal: not exported from the package.
59
+ */
60
+ export function pinPlan(count, next, elapsedMs) {
61
+ const slice = pinSliceSize(count, elapsedMs);
62
+ if (slice === 0)
63
+ return { runs: [], next: 0 };
64
+ const first = next >= 0 && next < count ? Math.floor(next) : 0;
65
+ const part = Math.min(slice, count - first);
66
+ const runs = [[first, part]];
67
+ if (part < slice)
68
+ runs.push([0, slice - part]);
69
+ return { runs, next: (first + slice) % count };
70
+ }
40
71
  export function createSatelliteLayer(three, scene, state, ratio) {
41
72
  if (!three.Points)
42
73
  throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
@@ -178,7 +209,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
178
209
  streak.visible = false;
179
210
  scene.add(streak);
180
211
  }
181
- entry = { source: group.satellites, points, geometry, material, positions, attribute, dim, dimVersion: -1, lines: [], linesAt: Number.NaN, linesWall: 0, style: "", streak, streakPositions, streakColours, streakAttribute, pinWall: 0, pinTime: 0 };
212
+ entry = { source: group.satellites, points, geometry, material, positions, attribute, dim, dimVersion: -1, lines: [], linesAt: Number.NaN, linesWall: 0, style: "", streak, streakPositions, streakColours, streakAttribute, pinWall: 0, pinTime: 0, pinNext: 0 };
182
213
  drawn.set(name, entry);
183
214
  }
184
215
  const style = `${group.color}|${group.size}|${ratio()}|${dotScale}|${state.orbitTint ? 1 : 0}`;
@@ -213,12 +244,21 @@ export function createSatelliteLayer(three, scene, state, ratio) {
213
244
  continue;
214
245
  }
215
246
  if (tooFast) {
216
- // pinned again about once a second, and at once when the time jumped (a date typed in, a scrub), so a place is never turned across days
217
- if (entry.pinWall === 0 || started - entry.pinWall >= 1000 || Math.abs(time - entry.pinTime) > 1500 * Math.abs(speed)) {
247
+ // pinned whole at the first frame and when the time jumped (a date typed in, a scrub), so a place is never turned across days; after that a slice a frame, each satellite again about once a second,
248
+ // so SGP4 never runs for the whole group (17,000 satellites take about 12 ms) in one frame
249
+ const total = group.satellites.count;
250
+ if (entry.pinWall === 0 || Math.abs(time - entry.pinTime) > 1500 * Math.abs(speed)) {
218
251
  group.satellites.pin(time);
219
- entry.pinWall = started;
220
- entry.pinTime = time;
252
+ entry.pinNext = 0;
253
+ }
254
+ else {
255
+ const plan = pinPlan(total, entry.pinNext, started - entry.pinWall);
256
+ for (const [first, part] of plan.runs)
257
+ group.satellites.pin(time, first, part);
258
+ entry.pinNext = plan.next;
221
259
  }
260
+ entry.pinWall = started;
261
+ entry.pinTime = time;
222
262
  const n = group.satellites.arc(time, span, entry.positions, entry.streakPositions);
223
263
  entry.attribute.needsUpdate = true;
224
264
  if (entry.streak) {
@@ -395,6 +395,15 @@ export interface SpaceDeps {
395
395
  onRideLost?: () => void;
396
396
  /** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
397
397
  onSatellitesError?: (error: unknown) => void;
398
+ /** The painted satellite trail. Read at every draw; nothing is uploaded while `step` returns false. */
399
+ paint?: {
400
+ data: Uint8Array;
401
+ width: number;
402
+ height: number;
403
+ step(ms: number): boolean;
404
+ span(): number;
405
+ on(): boolean;
406
+ };
398
407
  /** How the Sun, the planets and their moons are drawn; left out, plain spheres in the right colours (see `BodyPainter`). */
399
408
  painter?: BodyPainter;
400
409
  /** The models of large satellites, for a followed satellite (see `SatellitePainter`); none, and a satellite is a dot. */
@@ -6,9 +6,11 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
6
6
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
7
7
  import { faceOffset, ridePose } from "./ride.js";
8
8
  import { coverBody, covers } from "../sky/cover.js";
9
- import { createPlaceSprites } from "../markers/place-sprites.js";
9
+ import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
10
10
  import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
11
11
  import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
12
+ import { paintMinute } from "../paint/buffer.js";
13
+ import { createPaintTexture } from "../paint/texture.js";
12
14
  import { createBodyLabelLayer, newBodyLabelState } from "../realistic/body-label.js";
13
15
  import { createMeteorLayer, newMeteorState } from "../meteors/layer.js";
14
16
  import { createBorderLayer, newBorderState } from "../borders/layer.js";
@@ -186,6 +188,8 @@ export function createSpaceItem(model, deps) {
186
188
  fragmentShader: SURFACE_FRAG,
187
189
  uniforms: { dayMap: uniform.day, nightMap: uniform.night, waterMap: uniform.water, cloudMap: uniform.clouds, sunDir: sunEarth, sunLocal, cloudShift, lights: { value: 1 }, boost: { value: 0 }, ortho: { value: 0 } },
188
190
  });
191
+ const paint = createPaintTexture(three, deps.paint?.data ?? new Uint8Array(4), deps.paint?.width ?? 1, deps.paint?.height ?? 1);
192
+ Object.assign(earthMaterial.uniforms, paint.uniforms);
189
193
  const cloudMaterial = new three.ShaderMaterial({
190
194
  vertexShader: SURFACE_VERT,
191
195
  fragmentShader: CLOUD_FRAG,
@@ -283,8 +287,7 @@ export function createSpaceItem(model, deps) {
283
287
  let meteorTimer;
284
288
  let nameOn = null;
285
289
  let borders = null;
286
- let placeSprites = null;
287
- let placeSpritesTried = false;
290
+ const placeRings = { sprites: null, tried: false };
288
291
  let gridLayer = null;
289
292
  let marksTold = false;
290
293
  // the followed satellite's model: which satellite it is for, the drawing once it is made, and a count so that a model made for a satellite no longer followed is let go
@@ -348,6 +351,13 @@ export function createSpaceItem(model, deps) {
348
351
  glow.scale.setScalar(airTop(model.airThickness));
349
352
  earthMaterial.uniforms["lights"].value = model.light === "lit" ? 0 : 1;
350
353
  earthMaterial.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
354
+ if (deps.paint) {
355
+ if (deps.paint.step(model.time))
356
+ paint.upload();
357
+ paint.uniforms.paintNow.value = paintMinute(model.time);
358
+ paint.uniforms.paintSpan.value = deps.paint.span();
359
+ paint.uniforms.paintOn.value = deps.paint.on() ? 1 : 0;
360
+ }
351
361
  // the Moon, with its near side to the Earth
352
362
  moon.position.set(moonPos[0], moonPos[1], moonPos[2]);
353
363
  moon.scale.setScalar(RADIUS["Moon"][mode]);
@@ -777,13 +787,11 @@ export function createSpaceItem(model, deps) {
777
787
  });
778
788
  }
779
789
  const spriteData = deps.placeSprites?.() ?? null;
780
- if (spriteData && !placeSprites && !placeSpritesTried) {
781
- placeSprites = createPlaceSprites(three, earth, sunEarth);
782
- placeSpritesTried = true;
790
+ if (beginPlaceSprites(placeRings, spriteData, () => createPlaceSprites(three, earth, sunEarth))) {
783
791
  // told once: without `Points` the page's layer draws these rings itself
784
- deps.onPlaceRings?.(placeSprites !== null);
792
+ deps.onPlaceRings?.(placeRings.sprites !== null);
785
793
  }
786
- placeSprites?.sync(spriteData, model.ratio(), size.width, size.height, model.light === "lit");
794
+ placeRings.sprites?.sync(spriteData, model.ratio(), size.width, size.height, model.light === "lit");
787
795
  // the name written on the Earth: made the first time the settings ask for it; none while a ride along a body hides the Earth
788
796
  if (model.bodyLabel.settings && !nameOn)
789
797
  nameOn = createBodyLabelLayer(three, earth, model.bodyLabel, { invalidate: () => deps.invalidate(), ...(deps.onLabelError ? { onError: deps.onLabelError } : {}) });
@@ -921,7 +929,7 @@ export function createSpaceItem(model, deps) {
921
929
  meteors?.dispose();
922
930
  nameOn?.dispose();
923
931
  borders?.dispose();
924
- placeSprites?.dispose();
932
+ placeRings.sprites?.dispose();
925
933
  gridLayer?.dispose();
926
934
  modelSlot.turn += 1;
927
935
  dropModel();
@@ -942,6 +950,7 @@ export function createSpaceItem(model, deps) {
942
950
  }
943
951
  grid.dispose();
944
952
  solid.dispose();
953
+ paint.dispose();
945
954
  earthMaterial.dispose();
946
955
  cloudMaterial.dispose();
947
956
  atmosphereMaterial.dispose();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.37.0",
3
+ "version": "0.38.0",
4
4
  "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
5
5
  "keywords": [
6
6
  "earth",