@johnmorrisdotca/chikyu-earth 0.66.0 → 0.68.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.
@@ -3,7 +3,7 @@ export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SU
3
3
  export { fitDistance, plainPainter, type BodyDrawing, type RideTrack, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
4
4
  export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, rideGlideMs, ridePose, rideTiltLimits, rideTurnDegrees, type RideDrag, type RideFace, type RideInput, type RideLook, type RidePose, type RideModelSize, type RideViewpoint } from "./ride.ts";
5
5
  export { GLIDE_FLOOR_KM, satelliteGlide, satelliteGlideKm, type GlidePose, type Quat } from "./ride-glide.ts";
6
- export { earthHides, type SatelliteScreen } from "./satellite-layer.ts";
6
+ export { MAX_DOT_PX, dotPx, earthHides, type SatelliteScreen } from "./satellite-layer.ts";
7
7
  export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
8
8
  export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle, type RideUp } from "./north-up.ts";
9
9
  export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-satellite.ts";
@@ -5,7 +5,7 @@ export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SU
5
5
  export { fitDistance, plainPainter } from "./scene.js";
6
6
  export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, rideGlideMs, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
7
7
  export { GLIDE_FLOOR_KM, satelliteGlide, satelliteGlideKm } from "./ride-glide.js";
8
- export { earthHides } from "./satellite-layer.js";
8
+ export { MAX_DOT_PX, dotPx, earthHides } from "./satellite-layer.js";
9
9
  export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
10
10
  export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle } from "./north-up.js";
11
11
  export { genericSatellite, satelliteKind } from "./generic-satellite.js";
@@ -144,6 +144,32 @@ export declare const HOVER_FADE_MS = 180;
144
144
  * @returns The share still drawn, 0 when the fade is over.
145
145
  */
146
146
  export declare const fadeLeft: (elapsedMs: number, from: number) => number;
147
+ /**
148
+ * The most a satellite's dot is drawn across, in CSS pixels, however near the camera has come (the drawn size follows the Earth's size, up to 2.5 times): a dot a group asks to be larger than this keeps its own size and only stops growing.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * import { MAX_DOT_PX } from "@johnmorrisdotca/chikyu-earth/space";
153
+ *
154
+ * console.log(MAX_DOT_PX);
155
+ * ```
156
+ */
157
+ export declare const MAX_DOT_PX = 6;
158
+ /**
159
+ * How wide a group's dots are drawn, in CSS pixels: its size grown or shrunk with the Earth (`scale`), but never past `MAX_DOT_PX` (or the group's own size, if that is more).
160
+ *
161
+ * @param size - The group's dot size in CSS pixels.
162
+ * @param scale - How the Earth's drawn size has changed from the first (0.45 to 2.5).
163
+ * @returns The width to draw.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * import { dotPx } from "@johnmorrisdotca/chikyu-earth/space";
168
+ *
169
+ * console.log(dotPx(6, 1), dotPx(6, 2.5), dotPx(6, 0.45), dotPx(10, 2));
170
+ * ```
171
+ */
172
+ export declare function dotPx(size: number, scale: number): number;
147
173
  /** 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. */
148
174
  export declare const PIN_PERIOD_MS = 1000;
149
175
  /**
@@ -81,6 +81,36 @@ export const HOVER_FADE_MS = 180;
81
81
  export const fadeLeft = (elapsedMs, from) => from * (1 - Math.min(1, Math.max(0, elapsedMs) / HOVER_FADE_MS));
82
82
  const ORBIT_REFRESH_GAME_MS = 30 * 60_000;
83
83
  const ORBIT_REFRESH_WALL_MS = 1000;
84
+ /**
85
+ * The most a satellite's dot is drawn across, in CSS pixels, however near the camera has come (the drawn size follows the Earth's size, up to 2.5 times): a dot a group asks to be larger than this keeps its own size and only stops growing.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * import { MAX_DOT_PX } from "@johnmorrisdotca/chikyu-earth/space";
90
+ *
91
+ * console.log(MAX_DOT_PX);
92
+ * ```
93
+ */
94
+ export const MAX_DOT_PX = 6;
95
+ /** Dots narrower than this (CSS pixels) have no dark rim; it comes in over the next half. */
96
+ const RIM_MIN_PX = 5;
97
+ /**
98
+ * How wide a group's dots are drawn, in CSS pixels: its size grown or shrunk with the Earth (`scale`), but never past `MAX_DOT_PX` (or the group's own size, if that is more).
99
+ *
100
+ * @param size - The group's dot size in CSS pixels.
101
+ * @param scale - How the Earth's drawn size has changed from the first (0.45 to 2.5).
102
+ * @returns The width to draw.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import { dotPx } from "@johnmorrisdotca/chikyu-earth/space";
107
+ *
108
+ * console.log(dotPx(6, 1), dotPx(6, 2.5), dotPx(6, 0.45), dotPx(10, 2));
109
+ * ```
110
+ */
111
+ export function dotPx(size, scale) {
112
+ return Math.min(Math.max(MAX_DOT_PX, size), size * scale);
113
+ }
84
114
  const POINT_VERT = /* glsl */ `
85
115
  uniform float size;
86
116
  uniform float groupDim;
@@ -88,9 +118,11 @@ attribute float dim;
88
118
  attribute vec3 cls;
89
119
  varying float vDim;
90
120
  varying vec3 vCls;
121
+ varying float vPx;
91
122
  void main() {
92
123
  vDim = max(dim, groupDim);
93
124
  vCls = cls;
125
+ vPx = size;
94
126
  gl_PointSize = size;
95
127
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
96
128
  }`;
@@ -99,9 +131,11 @@ uniform vec3 tint;
99
131
  uniform float ring;
100
132
  uniform float byClass;
101
133
  uniform float rim;
134
+ uniform float rimMin;
102
135
  uniform float fade;
103
136
  varying float vDim;
104
137
  varying vec3 vCls;
138
+ varying float vPx;
105
139
  void main() {
106
140
  float d = length(gl_PointCoord - vec2(0.5));
107
141
  if (d > 0.5) discard;
@@ -116,7 +150,9 @@ void main() {
116
150
  gl_FragColor = vec4(ink, a * weak);
117
151
  } else {
118
152
  float rimEdge = smoothstep(0.28, 0.42, d);
119
- vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rimEdge * rim * (1.0 - 0.6 * estimated));
153
+ // the dark rim is for dots big enough to carry it: on a small one it would be most of the dot, and thousands of them turn black over the Earth
154
+ float big = smoothstep(rimMin, rimMin * 1.5, vPx);
155
+ vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rimEdge * rim * big * (1.0 - 0.6 * estimated));
120
156
  float a = smoothstep(0.50, 0.40, d);
121
157
  gl_FragColor = vec4(colour, a * weak * fade);
122
158
  }
@@ -238,7 +274,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
238
274
  const ink = new three.Color();
239
275
  let basis = 0;
240
276
  let lastEarthPx = 0;
241
- const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 }, byClass: { value: 0 }, rim: { value: 1 }, fade: { value: 1 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
277
+ const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 }, byClass: { value: 0 }, rim: { value: 1 }, rimMin: { value: RIM_MIN_PX }, fade: { value: 1 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
242
278
  const selectedPosition = new Float32Array(3);
243
279
  const selectedGeometry = new three.BufferGeometry();
244
280
  selectedGeometry.setAttribute("position", new three.BufferAttribute(selectedPosition, 3));
@@ -553,7 +589,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
553
589
  if (!group.visible)
554
590
  continue;
555
591
  marks += group.satellites.count;
556
- dotArea += group.satellites.count * (group.size * dotScale) ** 2;
592
+ dotArea += group.satellites.count * dotPx(group.size, dotScale) ** 2;
557
593
  }
558
594
  const dotFade = marks > 0 ? crowdFade(marks, dotArea / marks, radius, CROWD_COVER_DOTS) : 1;
559
595
  const streakFade = tooFast && capLength > 0 ? crowdFade(marks, Math.max(1, capLength * radius), radius, CROWD_COVER_STREAKS, false) : 1;
@@ -577,7 +613,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
577
613
  const dim = new three.BufferAttribute(group.satellites.dimmed, 1);
578
614
  geometry.setAttribute("dim", dim);
579
615
  geometry.setAttribute("cls", new three.BufferAttribute(group.satellites.classColour, 3));
580
- const material = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: group.size * ratio() }, tint: { value: new three.Color(group.color) }, ring: { value: 0 }, byClass: { value: 0 }, rim: { value: 1 }, fade: { value: 1 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
616
+ const material = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: dotPx(group.size, 1) * ratio() }, tint: { value: new three.Color(group.color) }, ring: { value: 0 }, byClass: { value: 0 }, rim: { value: 1 }, rimMin: { value: RIM_MIN_PX * ratio() }, fade: { value: 1 }, groupDim: { value: 0 } }, transparent: true, depthWrite: false });
581
617
  const points = new Points(geometry, material);
582
618
  points.frustumCulled = false;
583
619
  points.renderOrder = 5;
@@ -602,7 +638,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
602
638
  const style = `${group.color}|${group.size}|${ratio()}|${dotScale}|${state.orbitTint ? 1 : 0}`;
603
639
  if (style !== entry.style) {
604
640
  entry.style = style;
605
- entry.material.uniforms["size"].value = group.size * dotScale * ratio();
641
+ entry.material.uniforms["size"].value = dotPx(group.size, dotScale) * ratio();
642
+ entry.material.uniforms["rimMin"].value = RIM_MIN_PX * ratio();
606
643
  entry.material.uniforms["tint"].value.set(group.color);
607
644
  entry.material.uniforms["byClass"].value = state.orbitTint ? 1 : 0;
608
645
  ink.set(group.color);
@@ -778,7 +815,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
778
815
  const group = state.groups.get(name);
779
816
  if (!group)
780
817
  continue;
781
- entry.material.uniforms["size"].value = group.size * dotScale * ratio();
818
+ entry.material.uniforms["size"].value = dotPx(group.size, dotScale) * ratio();
782
819
  }
783
820
  },
784
821
  pick(x, y, camera, size, radius) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.66.0",
3
+ "version": "0.68.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",