@johnmorrisdotca/chikyu-earth 0.48.0 → 0.50.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.
@@ -56,7 +56,7 @@ export function longestStreak(segments, count, earthPx) {
56
56
  }
57
57
  return longest * earthPx;
58
58
  }
59
- export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, pathsDrawn: 0, pathDraws: 0 } });
59
+ export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, pathsDrawn: 0, pathDraws: 0, estimated: 0 } });
60
60
  /** The most orbits a group may draw all at once, one line each. */
61
61
  export const MAX_ORBIT_GROUP = 40;
62
62
  const ORBIT_POINTS = 120;
@@ -101,14 +101,19 @@ void main() {
101
101
  float d = length(gl_PointCoord - vec2(0.5));
102
102
  if (d > 0.5) discard;
103
103
  vec3 ink = byClass > 0.5 ? vCls : tint;
104
+ // a dim of 1 is an old element set; above 1 is an estimate (estimate-far): lighter, and fainter than an old one, so the two are told apart
105
+ float estimated = step(1.5, vDim);
106
+ float old = min(vDim, 1.0);
107
+ ink = mix(ink, vec3(1.0), 0.5 * estimated);
108
+ float weak = (1.0 - 0.7 * old) * (1.0 - 0.45 * estimated);
104
109
  if (ring > 0.5) {
105
110
  float a = smoothstep(0.30, 0.38, d) * (1.0 - smoothstep(0.44, 0.5, d));
106
- gl_FragColor = vec4(ink, a * (1.0 - 0.7 * vDim));
111
+ gl_FragColor = vec4(ink, a * weak);
107
112
  } else {
108
113
  float rimEdge = smoothstep(0.28, 0.42, d);
109
- vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rimEdge * rim);
114
+ vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rimEdge * rim * (1.0 - 0.6 * estimated));
110
115
  float a = smoothstep(0.50, 0.40, d);
111
- gl_FragColor = vec4(colour, a * (1.0 - 0.7 * vDim) * fade);
116
+ gl_FragColor = vec4(colour, a * weak * fade);
112
117
  }
113
118
  }`;
114
119
  /** 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. */
@@ -610,6 +615,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
610
615
  state.drawn.hoverPath = hoverLoop.visible;
611
616
  state.drawn.hoverOpacity = hoverLoop.visible ? hoverLine.material.opacity : 0;
612
617
  state.drawn.placed = placed;
618
+ let estimated = 0;
619
+ for (const group of state.groups.values())
620
+ if (group.visible)
621
+ estimated += group.satellites.estimatedCount;
622
+ state.drawn.estimated = estimated;
613
623
  state.drawn.segments = segments;
614
624
  state.drawn.longestStreakPx = longest;
615
625
  state.drawn.streakCapPx = capLength * radius;
@@ -716,7 +726,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
716
726
  else
717
727
  hidden = earthHides(c, world);
718
728
  }
719
- return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind, occluded: hidden };
729
+ return { x, y, visible: !behind && !hidden && edge === null, heightKm, edge, behind, occluded: hidden, estimated: find(ref)?.estimated(ref.index) ?? false };
720
730
  },
721
731
  pathAt(x, y, camera, size, radius) {
722
732
  if (!(radius > 0))
@@ -8,6 +8,7 @@ import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
8
8
  import { type ScaleMode } from "./scale.ts";
9
9
  import type { SatelliteRef } from "../satellites/types.ts";
10
10
  import { type RideFace, type RideLook, type RideModelSize, type RideViewpoint } from "./ride.ts";
11
+ import { type LightFade } from "../realistic/light-fade.ts";
11
12
  import type { SkyFrame } from "../sky/frame.ts";
12
13
  import type { PlaceView } from "../markers/places.ts";
13
14
  import { type PlaceSpriteData } from "../markers/place-sprites.ts";
@@ -170,6 +171,8 @@ export interface SpaceModel {
170
171
  focus: BodyName;
171
172
  /** How the Earth is lit (see `LightMode`); the Sun, the Moon and the planets keep their true places either way. */
172
173
  light: LightMode;
174
+ /** The cross-fade of the Earth's night lights between the true light and `lit`, stepped at each draw (src/realistic/light-fade.ts). */
175
+ lightFade: LightFade;
173
176
  /** How the painter draws the Sun, the planets and their moons (one of its `looks`, or `plain` for the sphere in the right colour); empty for its first. */
174
177
  bodies: string;
175
178
  /** Filled at each draw. */
@@ -6,6 +6,9 @@ import { createTileSet } from "../realistic/tile-set.js";
6
6
  import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
7
7
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
8
8
  import { faceOffset, outsidePose, ridePose } from "./ride.js";
9
+ import { stripLights } from "./model-lights.js";
10
+ import { newLightFade, stepLightFade } from "../realistic/light-fade.js";
11
+ import { prefersLessMotion } from "../meteors/note.js";
9
12
  import { genericSatellite, satelliteKind } from "./generic-satellite.js";
10
13
  import { followSpin } from "./follow.js";
11
14
  import { coverBody, covers } from "../sky/cover.js";
@@ -116,6 +119,7 @@ export const newSpaceModel = () => ({
116
119
  focus: "Earth",
117
120
  bodies: "",
118
121
  light: "sun",
122
+ lightFade: newLightFade(),
119
123
  drawn: null,
120
124
  painted: { bodies: 0, moons: 0, held: 0, moon: false, tiles: 0, mapped: 0, pending: 0 },
121
125
  lookups: 0,
@@ -401,8 +405,17 @@ export function createSpaceItem(model, deps) {
401
405
  let routeLayer = null;
402
406
  let marksTold = false;
403
407
  // 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
404
- const modelSlot = { key: "", drawing: null, turn: 0, parts: 0, axes: null };
408
+ const modelSlot = { key: "", drawing: null, turn: 0, parts: 0, axes: null, sun: null };
409
+ // The Sun's light for a generic satellite drawing, in the scene for good and dark (intensity 0) while no drawing is shown. Three counts the lights in the scene into the key of every program, so a light that came and went with a ride
410
+ // made a second program of the same code for each shader that was drawn while it was there (the Moon's, MODULES-1293): with the light always in the scene there is one.
411
+ const SunLight = three.DirectionalLight;
412
+ const sceneSun = SunLight ? new SunLight(0xfff4e0, 0) : undefined;
413
+ if (sceneSun)
414
+ scene.add(sceneSun);
405
415
  const dropModel = () => {
416
+ if (sceneSun)
417
+ sceneSun.intensity = 0;
418
+ modelSlot.sun = null;
406
419
  if (!modelSlot.drawing)
407
420
  return;
408
421
  scene.remove(modelSlot.drawing.object);
@@ -463,7 +476,11 @@ export function createSpaceItem(model, deps) {
463
476
  cloudShift.value = -(((model.time / 3_600_000) * model.cloudDrift) % 360) / 360;
464
477
  atmosphereMaterial.uniforms["thick"].value = model.airThickness;
465
478
  glow.scale.setScalar(airTop(model.airThickness));
466
- earthMaterial.uniforms["lights"].value = model.light === "lit" ? 0 : 1;
479
+ const fade = stepLightFade(model.lightFade, model.light === "lit", performance.now(), prefersLessMotion());
480
+ // one more frame while it moves, and none once it has arrived
481
+ if (fade.fading)
482
+ deps.invalidate();
483
+ earthMaterial.uniforms["lights"].value = 1 - fade.mix;
467
484
  earthMaterial.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
468
485
  if (deps.paint) {
469
486
  const changed = deps.paint.step(model.time);
@@ -862,6 +879,8 @@ export function createSpaceItem(model, deps) {
862
879
  const adopt = (made) => {
863
880
  made.object.matrixAutoUpdate = false;
864
881
  made.object.visible = false;
882
+ // the scene owns the Sun's light: a light the painter put in its model is switched off and its look taken for the scene's Sun to wear while the model is shown (a generic drawing has none of its own: it was given the scene's)
883
+ modelSlot.sun = stripLights(made.object);
865
884
  scene.add(made.object);
866
885
  modelSlot.drawing = made;
867
886
  // how many meshes the model is made of: a draw call each, which a test of the draw budget adds to the scene's own
@@ -873,7 +892,7 @@ export function createSpaceItem(model, deps) {
873
892
  deps.invalidate();
874
893
  };
875
894
  if (modelKey.startsWith("generic:"))
876
- adopt(genericSatellite(three, modelKey.slice(8)));
895
+ adopt(genericSatellite(three, modelKey.slice(8), sceneSun ? { sun: sceneSun } : undefined));
877
896
  else if (modelKey && satellitePainter && norad !== undefined) {
878
897
  void Promise.resolve(satellitePainter.make(three, norad, { look: "", invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() }))
879
898
  .then((made) => {
@@ -910,6 +929,11 @@ export function createSpaceItem(model, deps) {
910
929
  object.visible = true;
911
930
  const toSunNow = unit(frame.sun);
912
931
  modelSlot.drawing.light?.(toSunNow);
932
+ if (sceneSun && modelSlot.sun) {
933
+ sceneSun.color.setHex(modelSlot.sun.color);
934
+ sceneSun.intensity = modelSlot.sun.intensity;
935
+ sceneSun.position.set(toSunNow[0], toSunNow[1], toSunNow[2]);
936
+ }
913
937
  modelSlot.drawing.update?.({ toSun: toSunNow, ms: model.time, radiusPx: size.height * share });
914
938
  projected.set(shownSat.place[0], shownSat.place[1], shownSat.place[2]).project(camera);
915
939
  const sx = ((projected.x + 1) / 2) * size.width;
@@ -920,6 +944,8 @@ export function createSpaceItem(model, deps) {
920
944
  else {
921
945
  if (modelSlot.drawing)
922
946
  modelSlot.drawing.object.visible = false;
947
+ if (sceneSun)
948
+ sceneSun.intensity = 0;
923
949
  model.followModel = null;
924
950
  }
925
951
  const sunToSun = unit([-frame.sun[0], -frame.sun[1], -frame.sun[2]]);
@@ -1249,6 +1275,10 @@ export function createSpaceItem(model, deps) {
1249
1275
  routeLayer?.dispose();
1250
1276
  modelSlot.turn += 1;
1251
1277
  dropModel();
1278
+ if (sceneSun) {
1279
+ scene.remove(sceneSun);
1280
+ sceneSun.dispose?.();
1281
+ }
1252
1282
  layer?.dispose();
1253
1283
  model.pick = null;
1254
1284
  model.pathAt = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.48.0",
3
+ "version": "0.50.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",