@johnmorrisdotca/chikyu-earth 0.36.0 → 0.37.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.
@@ -14,6 +14,45 @@ const MAX_ABOVE_HORIZON = 20;
14
14
  * ```
15
15
  */
16
16
  export const RIDE_FOV = 60;
17
+ /**
18
+ * Every facing, in the order of a row of buttons.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { RIDE_FACES } from "@johnmorrisdotca/chikyu-earth/space";
23
+ *
24
+ * console.log(RIDE_FACES.join(" "));
25
+ * ```
26
+ */
27
+ export const RIDE_FACES = ["ahead", "behind", "left", "right", "down", "up"];
28
+ /** How far each facing turns from the way it goes, in degrees, to the left, in the view from the body. */
29
+ const FACE_TURN = { ahead: 0, behind: 180, left: 90, right: -90, down: 0, up: 0 };
30
+ /**
31
+ * Yaw and tilt, in radians, that put a camera looking at a satellite on a facing. `down` is straight above it, looking down at it and the Earth. `ahead` looks along the way it goes.
32
+ *
33
+ * @param face - The facing.
34
+ * @returns The yaw and tilt to give `aboveAxes`.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { faceOffset } from "@johnmorrisdotca/chikyu-earth/space";
39
+ *
40
+ * console.log(faceOffset("down").tilt, faceOffset("ahead").tilt > 1);
41
+ * ```
42
+ */
43
+ export function faceOffset(face) {
44
+ if (face === "up")
45
+ return { yaw: 0, tilt: Math.PI };
46
+ if (face === "ahead")
47
+ return { yaw: 0, tilt: Math.PI / 2 };
48
+ if (face === "behind")
49
+ return { yaw: 0, tilt: -Math.PI / 2 };
50
+ if (face === "left")
51
+ return { yaw: Math.PI / 2, tilt: Math.PI / 2 };
52
+ if (face === "right")
53
+ return { yaw: -Math.PI / 2, tilt: Math.PI / 2 };
54
+ return { yaw: 0, tilt: 0 };
55
+ }
17
56
  /**
18
57
  * The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 5 and 100.
19
58
  *
@@ -112,16 +151,19 @@ export function ridePose(input) {
112
151
  }
113
152
  ahead = unit(ahead);
114
153
  const earthRadiusDegrees = distance <= 1 ? 90 : Math.asin(1 / distance) / RAD;
154
+ const faced = input.look === "horizon" && input.face ? FACE_TURN[input.face] : 0;
115
155
  const base = input.look === "horizon" ? Math.max(0, earthRadiusDegrees - 12) * RAD : 0;
116
156
  const fov = rideFov(input.zoom);
117
- const turn = (input.turn ?? input.yaw * (GRAB * fov / 180)) * RAD;
157
+ const turn = ((input.turn ?? input.yaw * (GRAB * fov / 180)) + faced) * RAD;
118
158
  const lift = input.tilt * (GRAB * fov / 60) * RAD;
159
+ const rest = input.face === "down" ? -Math.PI / 2 : input.face === "up" ? Math.PI / 2 : base - Math.PI / 2;
160
+ const cap = Math.max(MAX_ABOVE_HORIZON * RAD, rest);
119
161
  if (input.look === "horizon") {
120
162
  // looking round on the spot: a drag sideways turns the camera about the local vertical, all the way round, and a drag up or down tips it up or down in the vertical plane it faces, from straight down to a little above the horizon,
121
- // so the horizon stays level and nothing rolls
163
+ // so the horizon stays level and nothing rolls. A facing (`up`, `down`, `ahead`, ...) is where that drag starts.
122
164
  const zenith = scale(nadir, -1);
123
165
  const heading = add(scale(ahead, Math.cos(turn)), scale(cross(zenith, ahead), Math.sin(turn)));
124
- const elevation = Math.max(-Math.PI / 2, Math.min(MAX_ABOVE_HORIZON * RAD, base - Math.PI / 2 - lift));
166
+ const elevation = Math.max(-Math.PI / 2, Math.min(cap, rest - lift));
125
167
  const forward = add(scale(heading, Math.cos(elevation)), scale(zenith, Math.sin(elevation)));
126
168
  const up = add(scale(heading, -Math.sin(elevation)), scale(zenith, Math.cos(elevation)));
127
169
  return { position: [input.position[0], input.position[1], input.position[2]], forward, up, fov, earthRadiusDegrees };
@@ -19,9 +19,13 @@ export interface SatelliteState {
19
19
  /** The groups whose members are ringed and named (`labelSatellites`): the scene tells the page where each is, at every draw. */
20
20
  marked: Set<string>;
21
21
  /** Written at each draw: satellites placed, whether the clock is too fast for the groups, and the milliseconds the last update took. */
22
+ /** Colour each dot by its orbit class. Off by default: a group keeps the one colour it was given. */
23
+ orbitTint: boolean;
22
24
  drawn: {
23
25
  placed: number;
26
+ segments: number;
24
27
  tooFast: boolean;
28
+ dotScale: number;
25
29
  updateMs: number;
26
30
  maxUpdateMs: number;
27
31
  updates: number;
@@ -56,8 +60,10 @@ export interface SatelliteLayer {
56
60
  width: number;
57
61
  height: number;
58
62
  }): SatelliteScreen | null;
59
- /** Place every shown group for `model.time` and the chosen satellite exactly. */
60
- update(time: number, speed: number): void;
63
+ /** Place every shown group for `model.time` and the chosen satellite exactly. `earthPx` is the Earth's radius on the screen, so a dot grows as the view zooms in. */
64
+ update(time: number, speed: number, earthPx?: number): void;
65
+ /** Set the dot size from the Earth's radius on the screen for this frame, after the camera is known. */
66
+ resize(earthPx: number): void;
61
67
  /** The satellite nearest to a point of the view (CSS pixels) within `radius`, if one is in front of the Earth. */
62
68
  pick(x: number, y: number, camera: THREE.Camera, size: {
63
69
  width: number;
@@ -1,5 +1,5 @@
1
1
  import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
2
- export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), drawn: { placed: 0, tooFast: false, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0 } });
2
+ export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), orbitTint: false, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0 } });
3
3
  /** The most orbits a group may draw all at once, one line each. */
4
4
  export const MAX_ORBIT_GROUP = 40;
5
5
  const ORBIT_POINTS = 120;
@@ -8,36 +8,62 @@ const ORBIT_REFRESH_WALL_MS = 1000;
8
8
  const POINT_VERT = /* glsl */ `
9
9
  uniform float size;
10
10
  attribute float dim;
11
+ attribute vec3 cls;
11
12
  varying float vDim;
13
+ varying vec3 vCls;
12
14
  void main() {
13
15
  vDim = dim;
16
+ vCls = cls;
14
17
  gl_PointSize = size;
15
18
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
16
19
  }`;
17
20
  const POINT_FRAG = /* glsl */ `
18
21
  uniform vec3 tint;
19
22
  uniform float ring;
23
+ uniform float byClass;
20
24
  varying float vDim;
25
+ varying vec3 vCls;
21
26
  void main() {
22
27
  float d = length(gl_PointCoord - vec2(0.5));
23
28
  if (d > 0.5) discard;
24
- float a = ring > 0.5 ? smoothstep(0.30, 0.38, d) * (1.0 - smoothstep(0.44, 0.5, d)) : smoothstep(0.5, 0.2, d);
25
- gl_FragColor = vec4(tint, a * (1.0 - 0.7 * vDim));
29
+ vec3 ink = byClass > 0.5 ? vCls : tint;
30
+ if (ring > 0.5) {
31
+ float a = smoothstep(0.30, 0.38, d) * (1.0 - smoothstep(0.44, 0.5, d));
32
+ gl_FragColor = vec4(ink, a * (1.0 - 0.7 * vDim));
33
+ } else {
34
+ float rim = smoothstep(0.28, 0.42, d);
35
+ vec3 colour = mix(ink, vec3(0.04, 0.05, 0.08), rim);
36
+ float a = smoothstep(0.50, 0.40, d);
37
+ gl_FragColor = vec4(colour, a * (1.0 - 0.7 * vDim));
38
+ }
26
39
  }`;
27
40
  export function createSatelliteLayer(three, scene, state, ratio) {
28
41
  if (!three.Points)
29
42
  throw new Error("Satellites need `Points` from three.js: add it to the parts the three loader hands over (see setThreeLoader)");
30
43
  const Points = three.Points;
44
+ const LineSegments = three.LineSegments;
45
+ let warned = false;
46
+ /** Without `LineSegments` the streaks cannot be drawn, so above the interpolation limit the dots alone are shown. Said once, in the console, and nothing else is lost. */
47
+ const warnNoStreaks = () => {
48
+ if (warned)
49
+ return;
50
+ warned = true;
51
+ console.warn("chikyu-earth: the three.js parts handed over lack `LineSegments`, so above 60 times real time the satellites are dots without streaks. Add `LineSegments` to the parts the three loader hands over (see setThreeLoader).");
52
+ };
31
53
  const drawn = new Map();
32
54
  const tmp = new Float64Array(6);
33
55
  const projected = new three.Vector3();
34
56
  const world = new three.Vector3();
35
57
  const view = new three.Vector3();
36
- const selectedMaterial = new three.ShaderMaterial({ vertexShader: POINT_VERT, fragmentShader: POINT_FRAG, uniforms: { size: { value: 14 }, tint: { value: new three.Color("#ffffff") }, ring: { value: 1 } }, transparent: true, depthWrite: false });
58
+ const ink = new three.Color();
59
+ let basis = 0;
60
+ let lastGame = 0;
61
+ 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 } }, transparent: true, depthWrite: false });
37
62
  const selectedPosition = new Float32Array(3);
38
63
  const selectedGeometry = new three.BufferGeometry();
39
64
  selectedGeometry.setAttribute("position", new three.BufferAttribute(selectedPosition, 3));
40
65
  selectedGeometry.setAttribute("dim", new three.BufferAttribute(new Float32Array(1), 1));
66
+ selectedGeometry.setAttribute("cls", new three.BufferAttribute(new Float32Array([1, 1, 1]), 3));
41
67
  const selectedPoints = new Points(selectedGeometry, selectedMaterial);
42
68
  selectedPoints.frustumCulled = false;
43
69
  selectedPoints.renderOrder = 6;
@@ -56,6 +82,11 @@ export function createSatelliteLayer(three, scene, state, ratio) {
56
82
  scene.remove(entry.points);
57
83
  entry.geometry.dispose();
58
84
  entry.material.dispose();
85
+ if (entry.streak) {
86
+ scene.remove(entry.streak);
87
+ entry.streak.geometry.dispose();
88
+ entry.streak.material.dispose();
89
+ }
59
90
  for (const line of entry.lines) {
60
91
  scene.remove(line.loop);
61
92
  line.geometry.dispose();
@@ -98,10 +129,17 @@ export function createSatelliteLayer(three, scene, state, ratio) {
98
129
  };
99
130
  const find = (ref) => state.groups.get(ref.group)?.satellites;
100
131
  return {
101
- update(time, speed) {
132
+ update(time, speed, earthPx = 0) {
102
133
  const started = performance.now();
103
134
  const tooFast = Math.abs(speed) > MAX_SATELLITE_SPEED;
104
135
  const step = Math.min(60_000, Math.max(1000, Math.abs(speed) * 1000));
136
+ if (basis === 0 && earthPx > 0)
137
+ basis = earthPx;
138
+ const dotScale = basis > 0 && earthPx > 0 ? Math.min(2.5, Math.max(0.45, Math.sqrt(earthPx / basis))) : 1;
139
+ const frameMs = speed * (1000 / 30);
140
+ const since = lastGame === 0 ? frameMs : time - lastGame;
141
+ const span = tooFast ? (Math.abs(since) > 0 && Math.abs(since) < Math.abs(frameMs) * 4 ? since : frameMs) : 0;
142
+ lastGame = time;
105
143
  for (const [name, entry] of drawn) {
106
144
  if (state.groups.get(name)?.satellites !== entry.source) {
107
145
  drop(entry);
@@ -109,45 +147,110 @@ export function createSatelliteLayer(three, scene, state, ratio) {
109
147
  }
110
148
  }
111
149
  let placed = 0;
150
+ let segments = 0;
112
151
  for (const [name, group] of state.groups) {
113
152
  let entry = drawn.get(name);
114
153
  if (!entry) {
115
- const positions = new Float32Array(group.satellites.count * 3);
154
+ const count = group.satellites.count;
155
+ const positions = new Float32Array(count * 3);
116
156
  const geometry = new three.BufferGeometry();
117
157
  const attribute = new three.BufferAttribute(positions, 3);
118
158
  geometry.setAttribute("position", attribute);
119
159
  const dim = new three.BufferAttribute(group.satellites.dimmed, 1);
120
160
  geometry.setAttribute("dim", dim);
121
- 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 } }, transparent: true, depthWrite: false });
161
+ geometry.setAttribute("cls", new three.BufferAttribute(group.satellites.classColour, 3));
162
+ 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 } }, transparent: true, depthWrite: false });
122
163
  const points = new Points(geometry, material);
123
164
  points.frustumCulled = false;
124
165
  points.renderOrder = 5;
125
166
  scene.add(points);
126
- entry = { source: group.satellites, points, geometry, material, positions, attribute, dim, dimVersion: -1, lines: [], linesAt: Number.NaN, linesWall: 0, style: "" };
167
+ const streakPositions = new Float32Array(count * 6);
168
+ const streakColours = new Float32Array(count * 6);
169
+ const streakGeometry = new three.BufferGeometry();
170
+ const streakAttribute = new three.BufferAttribute(streakPositions, 3);
171
+ streakGeometry.setAttribute("position", streakAttribute);
172
+ streakGeometry.setAttribute("color", new three.BufferAttribute(streakColours, 3));
173
+ let streak = null;
174
+ if (LineSegments) {
175
+ streak = new LineSegments(streakGeometry, new three.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.95 }));
176
+ streak.frustumCulled = false;
177
+ streak.renderOrder = 4;
178
+ streak.visible = false;
179
+ scene.add(streak);
180
+ }
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 };
127
182
  drawn.set(name, entry);
128
183
  }
129
- const style = `${group.color}|${group.size}|${ratio()}`;
184
+ const style = `${group.color}|${group.size}|${ratio()}|${dotScale}|${state.orbitTint ? 1 : 0}`;
130
185
  if (style !== entry.style) {
131
186
  entry.style = style;
132
- entry.material.uniforms["size"].value = group.size * ratio();
187
+ entry.material.uniforms["size"].value = group.size * dotScale * ratio();
133
188
  entry.material.uniforms["tint"].value.set(group.color);
189
+ entry.material.uniforms["byClass"].value = state.orbitTint ? 1 : 0;
190
+ ink.set(group.color);
191
+ const colours = group.satellites.classColour;
192
+ for (let i = 0; i < group.satellites.count; i += 1) {
193
+ const r = state.orbitTint ? colours[i * 3] : ink.r;
194
+ const g = state.orbitTint ? colours[i * 3 + 1] : ink.g;
195
+ const b = state.orbitTint ? colours[i * 3 + 2] : ink.b;
196
+ for (const end of [0, 1]) {
197
+ const c = i * 6 + end * 3;
198
+ entry.streakColours[c] = r;
199
+ entry.streakColours[c + 1] = g;
200
+ entry.streakColours[c + 2] = b;
201
+ }
202
+ }
203
+ if (entry.streak)
204
+ entry.streak.geometry.getAttribute("color").needsUpdate = true;
134
205
  }
135
- const show = group.visible && !tooFast;
206
+ const show = group.visible;
136
207
  entry.points.visible = show;
137
208
  if (!show) {
209
+ if (entry.streak)
210
+ entry.streak.visible = false;
138
211
  for (const line of entry.lines)
139
212
  line.loop.visible = false;
140
213
  continue;
141
214
  }
142
- group.satellites.setStep(step);
143
- group.satellites.at(time, entry.positions);
144
- entry.attribute.needsUpdate = true;
145
- if (entry.dimVersion !== group.satellites.dimVersion) {
146
- entry.dimVersion = group.satellites.dimVersion;
147
- entry.dim.needsUpdate = true;
215
+ 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)) {
218
+ group.satellites.pin(time);
219
+ entry.pinWall = started;
220
+ entry.pinTime = time;
221
+ }
222
+ const n = group.satellites.arc(time, span, entry.positions, entry.streakPositions);
223
+ entry.attribute.needsUpdate = true;
224
+ if (entry.streak) {
225
+ entry.streakAttribute.needsUpdate = true;
226
+ entry.streak.visible = n > 0 && Math.abs(span) > 0;
227
+ }
228
+ else
229
+ warnNoStreaks();
230
+ if (entry.dimVersion !== group.satellites.dimVersion) {
231
+ entry.dimVersion = group.satellites.dimVersion;
232
+ entry.dim.needsUpdate = true;
233
+ }
234
+ for (const line of entry.lines)
235
+ line.loop.visible = false;
236
+ placed += n;
237
+ if (entry.streak)
238
+ segments += n;
239
+ }
240
+ else {
241
+ if (entry.streak)
242
+ entry.streak.visible = false;
243
+ entry.pinWall = 0;
244
+ group.satellites.setStep(step);
245
+ group.satellites.at(time, entry.positions);
246
+ entry.attribute.needsUpdate = true;
247
+ if (entry.dimVersion !== group.satellites.dimVersion) {
248
+ entry.dimVersion = group.satellites.dimVersion;
249
+ entry.dim.needsUpdate = true;
250
+ }
251
+ placed += group.satellites.placed;
252
+ orbitsOf(entry, group, time, started);
148
253
  }
149
- placed += group.satellites.placed;
150
- orbitsOf(entry, group, time, started);
151
254
  }
152
255
  const chosen = state.selected;
153
256
  const set = chosen ? find(chosen) : undefined;
@@ -174,6 +277,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
174
277
  selectedKey = "";
175
278
  }
176
279
  state.drawn.placed = placed;
280
+ state.drawn.segments = segments;
281
+ state.drawn.dotScale = dotScale;
177
282
  state.drawn.tooFast = tooFast;
178
283
  state.drawn.updateMs = performance.now() - started;
179
284
  if (state.drawn.updateMs > state.drawn.maxUpdateMs)
@@ -181,6 +286,20 @@ export function createSatelliteLayer(three, scene, state, ratio) {
181
286
  state.drawn.updates += 1;
182
287
  state.drawn.totalMs += state.drawn.updateMs;
183
288
  },
289
+ resize(earthPx) {
290
+ if (!(earthPx > 0))
291
+ return;
292
+ if (basis === 0)
293
+ basis = earthPx;
294
+ const dotScale = Math.min(2.5, Math.max(0.45, Math.sqrt(earthPx / basis)));
295
+ state.drawn.dotScale = dotScale;
296
+ for (const [name, entry] of drawn) {
297
+ const group = state.groups.get(name);
298
+ if (!group)
299
+ continue;
300
+ entry.material.uniforms["size"].value = group.size * dotScale * ratio();
301
+ }
302
+ },
184
303
  pick(x, y, camera, size, radius) {
185
304
  let best = null;
186
305
  let bestD = radius * radius;
@@ -6,7 +6,7 @@ import type { LightMode } from "../realistic/earth.ts";
6
6
  import { type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
7
7
  import { type ScaleMode } from "./scale.ts";
8
8
  import type { SatelliteRef } from "../satellites/types.ts";
9
- import { type RideLook } from "./ride.ts";
9
+ import { type RideFace, type RideLook } from "./ride.ts";
10
10
  import type { SkyFrame } from "../sky/frame.ts";
11
11
  import type { PlaceView } from "../markers/places.ts";
12
12
  import { type PlaceSpriteData } from "../markers/place-sprites.ts";
@@ -92,6 +92,8 @@ export interface RideState {
92
92
  /** `from`: the camera is at the body, looking at the Earth. `follow`: the camera keeps a fixed distance from it, looking at it. `above` (a satellite): the camera is on the line from the Earth's centre through the satellite, looking straight down. */
93
93
  view: "from" | "follow" | "above";
94
94
  look: RideLook;
95
+ /** The facing the yaw and tilt look round from, or null. */
96
+ face: RideFace | null;
95
97
  /** For `follow` a satellite: how far the camera keeps, in kilometres. */
96
98
  distanceKm: number;
97
99
  }
@@ -4,7 +4,7 @@ import { BODY_FRAG, CLOUD_FRAG, GLOW_FRAG, GLOW_VERT, SURFACE_FRAG, SURFACE_VERT
4
4
  import { createTextureSet } from "../realistic/textures.js";
5
5
  import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
6
6
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
7
- import { ridePose } from "./ride.js";
7
+ import { faceOffset, ridePose } from "./ride.js";
8
8
  import { coverBody, covers } from "../sky/cover.js";
9
9
  import { createPlaceSprites } from "../markers/place-sprites.js";
10
10
  import { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
@@ -414,7 +414,7 @@ export function createSpaceItem(model, deps) {
414
414
  deps.onSatellitesError?.(error);
415
415
  }
416
416
  }
417
- layer?.update(model.time, model.speed);
417
+ layer?.update(model.time, model.speed, model.drawn?.radiusPx ?? 0);
418
418
  model.pick = layer ? (x, y, radius) => layer.pick(x, y, camera, size, radius) : null;
419
419
  // the camera: looks at the focus body from the direction the sky was in when it was last moved, turned by yaw and tilt, as far as the zoom says; or, riding along, sits at the
420
420
  // body and looks at the Earth
@@ -468,7 +468,7 @@ export function createSpaceItem(model, deps) {
468
468
  let fovNow = FOV;
469
469
  let distance = 0;
470
470
  if (rideFrom) {
471
- const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, turn: model.rideTurn });
471
+ const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, turn: model.rideTurn, ...(ride.face ? { face: ride.face } : {}) });
472
472
  model.rideDistance = Math.hypot(...rideFrom.position);
473
473
  camera.position.set(pose.position[0], pose.position[1], pose.position[2]);
474
474
  camera.up.set(pose.up[0], pose.up[1], pose.up[2]);
@@ -500,11 +500,12 @@ export function createSpaceItem(model, deps) {
500
500
  const lon = model.centre.lon - way * model.view.yaw;
501
501
  const lat = Math.max(-90, Math.min(90, baseLat - way * model.view.tilt));
502
502
  const aim = direction(spin + lon, lat);
503
- if (followed && ride && ride.view === "above") {
504
- // above the satellite: on the line from the Earth's centre through it, looking straight down at it, the way it is going at the top of the picture; the satellite stays in the middle and the Earth turns beneath.
505
- // A drag turns the picture about the satellite (yaw) and tips the camera back or ahead of it (tilt).
503
+ if (followed && ride && (ride.view === "above" || (ride.view === "follow" && ride.face))) {
504
+ // above the satellite, or a follow that was asked to face a way: on a line from the satellite, looking at it. With no facing, straight above, the way it is going at the top of the picture.
505
+ // A facing puts the camera ahead, behind, left, right, down or up; a drag turns and tips from there.
506
506
  distance = Math.max(1e-4, ride.distanceKm / 6371 / Math.max(1e-9, model.view.zoom));
507
- const up = aboveAxes(followed.place, followed.velocity, model.view.yaw * RAD, Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
507
+ const base = ride.face ? faceOffset(ride.face) : { yaw: 0, tilt: 0 };
508
+ const up = aboveAxes(followed.place, followed.velocity, base.yaw + model.view.yaw * RAD, base.tilt + Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
508
509
  target.set(focusPos[0], focusPos[1], focusPos[2]);
509
510
  camera.position.set(target.x + up.offset[0] * distance, target.y + up.offset[1] * distance, target.z + up.offset[2] * distance);
510
511
  camera.up.set(up.up[0], up.up[1], up.up[2]);
@@ -579,6 +580,7 @@ export function createSpaceItem(model, deps) {
579
580
  for (const name of BODY_NAMES)
580
581
  px[name] = radiusPxOf(name);
581
582
  model.drawn = { frame, distance, radiusPx: px.Earth };
583
+ layer?.resize(px.Earth);
582
584
  let paintedBodies = sunSlot.drawing ? 1 : 0;
583
585
  for (const p of planets.values())
584
586
  if (p.slot.drawing)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.36.0",
3
+ "version": "0.37.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",