@johnmorrisdotca/chikyu-earth 0.61.0 → 0.63.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 +22 -0
- package/README.md +3 -3
- package/dist/realistic/cloud-fade.d.ts +22 -0
- package/dist/realistic/cloud-fade.js +44 -0
- package/dist/realistic/earth.d.ts +3 -0
- package/dist/realistic/earth.js +6 -1
- package/dist/realistic/element-base.d.ts +2 -0
- package/dist/realistic/element-base.js +8 -1
- package/dist/realistic/shaders.d.ts +1 -1
- package/dist/realistic/shaders.js +10 -0
- package/dist/space/element-base.d.ts +92 -4
- package/dist/space/element-base.js +220 -33
- package/dist/space/fly.d.ts +292 -0
- package/dist/space/fly.js +293 -0
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/scene.d.ts +5 -0
- package/dist/space/scene.js +51 -5
- package/package.json +1 -1
package/dist/space/scene.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
|
8
8
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
9
9
|
import { faceOffset, outsidePose, rideGlideMs, ridePose } from "./ride.js";
|
|
10
10
|
import { stripLights } from "./model-lights.js";
|
|
11
|
+
import { cloudFade, CLOUD_FADE_DEFAULT, CLOUD_WIDTH } from "../realistic/cloud-fade.js";
|
|
11
12
|
import { newLightFade, stepLightFade } from "../realistic/light-fade.js";
|
|
12
13
|
import { prefersLessMotion } from "../meteors/note.js";
|
|
13
14
|
import { genericSatellite, satelliteKind } from "./generic-satellite.js";
|
|
@@ -31,6 +32,8 @@ import { subsolarPoint, unitVector } from "../realistic/sun.js";
|
|
|
31
32
|
const MAX_MARKED = 80;
|
|
32
33
|
const RAD = Math.PI / 180;
|
|
33
34
|
const FOV = 35;
|
|
35
|
+
/** The nearest a camera comes to the Earth's centre, in Earth radii: 1 km above the ground. A ride (or a glide into or out of one) that would put the camera lower, or under the ground, puts it here instead (`clearGround`). */
|
|
36
|
+
const GROUND_CLEAR = 1 + 1 / 6371;
|
|
34
37
|
const newEase = () => ({ cur: Number.NaN, from: Number.NaN, to: Number.NaN, start: 0 });
|
|
35
38
|
/** Moves an ease towards `to`: at once when it is new or `ms` is 0 (reduced motion), else over `ms` milliseconds with a smooth step. True while it is still on its way. */
|
|
36
39
|
function stepEase(e, to, now, ms, fresh) {
|
|
@@ -112,10 +115,13 @@ export const newSpaceModel = () => ({
|
|
|
112
115
|
camera: "space",
|
|
113
116
|
airThickness: AIR_THICKNESS_DEFAULT,
|
|
114
117
|
cloudDrift: 0,
|
|
118
|
+
cloudFade: CLOUD_FADE_DEFAULT,
|
|
119
|
+
cloudShown: 1,
|
|
115
120
|
cameraSpin: null,
|
|
116
121
|
follow: 0,
|
|
117
122
|
earth: { size: DEFAULT_EARTH_SIZE, x: 0.5, y: 0.5 },
|
|
118
123
|
fit: fitDistance(DEFAULT_EARTH_SIZE, 1),
|
|
124
|
+
nearest: 1.05,
|
|
119
125
|
orbits: true,
|
|
120
126
|
labels: true,
|
|
121
127
|
stepMs: 1000,
|
|
@@ -159,6 +165,32 @@ const unit = (v) => {
|
|
|
159
165
|
const l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
160
166
|
return [v[0] / l, v[1] / l, v[2] / l];
|
|
161
167
|
};
|
|
168
|
+
/**
|
|
169
|
+
* Keep a camera at least `GROUND_CLEAR` from the Earth's centre. One looking at a point above the ground (`at`) is brought towards it along its line of sight, to where that line comes out of the ground, so the point stays where it is in the
|
|
170
|
+
* picture; any other is moved out along its line from the centre. Changes `camera` in place, and brings the near plane in to half its height when it moves it.
|
|
171
|
+
*/
|
|
172
|
+
function clearGround(camera, at) {
|
|
173
|
+
const p = camera.position;
|
|
174
|
+
const from = p.length();
|
|
175
|
+
if (from >= GROUND_CLEAR)
|
|
176
|
+
return;
|
|
177
|
+
const atFrom = at ? Math.hypot(at[0], at[1], at[2]) : 0;
|
|
178
|
+
if (at && atFrom > GROUND_CLEAR) {
|
|
179
|
+
// the first point from `at` towards the camera where the line is GROUND_CLEAR from the centre
|
|
180
|
+
const d = [p.x - at[0], p.y - at[1], p.z - at[2]];
|
|
181
|
+
const a = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
|
|
182
|
+
const b = 2 * (at[0] * d[0] + at[1] * d[1] + at[2] * d[2]);
|
|
183
|
+
const c = atFrom * atFrom - GROUND_CLEAR * GROUND_CLEAR;
|
|
184
|
+
const t = (-b - Math.sqrt(Math.max(0, b * b - 4 * a * c))) / (2 * a);
|
|
185
|
+
p.set(at[0] + d[0] * t, at[1] + d[1] * t, at[2] + d[2] * t);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
if (from < 1e-9)
|
|
189
|
+
p.set(0, 0, 1);
|
|
190
|
+
p.multiplyScalar(GROUND_CLEAR / p.length());
|
|
191
|
+
}
|
|
192
|
+
camera.near = Math.min(camera.near, (GROUND_CLEAR - 1) * 0.5);
|
|
193
|
+
}
|
|
162
194
|
/** A square facing +z, 2 x 2, with uvs 0 to 1. */
|
|
163
195
|
function quad(three) {
|
|
164
196
|
const g = new three.BufferGeometry();
|
|
@@ -275,7 +307,7 @@ export function createSpaceItem(model, deps) {
|
|
|
275
307
|
const cloudMaterial = new three.ShaderMaterial({
|
|
276
308
|
vertexShader: SURFACE_VERT,
|
|
277
309
|
fragmentShader: CLOUD_FRAG,
|
|
278
|
-
uniforms: { cloudMap: uniform.clouds, sunDir: sunEarth, shift: cloudShift, opacity: { value: 0.9 } },
|
|
310
|
+
uniforms: { cloudMap: uniform.clouds, sunDir: sunEarth, shift: cloudShift, opacity: { value: 0.9 }, fadeGone: { value: 0 }, texelK: { value: 0 } },
|
|
279
311
|
transparent: true,
|
|
280
312
|
depthWrite: false,
|
|
281
313
|
});
|
|
@@ -706,22 +738,30 @@ export function createSpaceItem(model, deps) {
|
|
|
706
738
|
// north up (the view above a satellite only): the picture is turned so north is at the top, less near a pole; a drag turns it from there
|
|
707
739
|
const north = ride.view === "above" && ride.up === "north" ? northUpYaw(followed.place, followed.velocity) : null;
|
|
708
740
|
const up = aboveAxes(followed.place, followed.velocity, base.yaw + (north ? north.yaw * north.weight : 0) + model.view.yaw * RAD, base.tilt + Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
|
|
741
|
+
// a facing along the ground (ahead, behind, left, right) looks along the top `aboveAxes` gives, so that top would be the line of sight itself and the camera's turn would come from rounding, a different one each draw:
|
|
742
|
+
// the top of the picture is the sky there (straight away from the Earth, square to the line of sight)
|
|
743
|
+
const sky = unit(followed.place);
|
|
744
|
+
const skyward = sky[0] * up.offset[0] + sky[1] * up.offset[1] + sky[2] * up.offset[2];
|
|
745
|
+
const top = Math.abs(Math.sin(base.tilt)) > 0.5 ? unit([sky[0] - skyward * up.offset[0], sky[1] - skyward * up.offset[1], sky[2] - skyward * up.offset[2]]) : up.up;
|
|
709
746
|
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
710
747
|
camera.position.set(target.x + up.offset[0] * distance, target.y + up.offset[1] * distance, target.z + up.offset[2] * distance);
|
|
711
|
-
camera.up.set(up.up[0], up.up[1], up.up[2]);
|
|
712
|
-
camera.lookAt(target);
|
|
713
748
|
camera.near = Math.max(1e-4, distance * 0.02);
|
|
749
|
+
clearGround(camera, focusPos);
|
|
750
|
+
camera.up.set(top[0], top[1], top[2]);
|
|
751
|
+
camera.lookAt(target);
|
|
714
752
|
camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
|
|
715
753
|
}
|
|
716
754
|
else {
|
|
717
755
|
if (way === 1 && focus === "Earth")
|
|
718
756
|
model.lookBase = { lon: model.centre.lon + spin - frame.spin, lat: baseLat };
|
|
719
|
-
distance = Math.max(1.05 * focusRadius, (fit * focusRadius) / Math.max(1e-9, model.view.zoom));
|
|
757
|
+
distance = Math.max((focus === "Earth" ? model.nearest : 1.05) * focusRadius, (fit * focusRadius) / Math.max(1e-9, model.view.zoom));
|
|
720
758
|
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
721
759
|
camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
|
|
722
760
|
camera.up.set(0, 1, 0);
|
|
761
|
+
// within about 130 km of the ground (a fly-to's descent) the near plane comes in to half the height, or it would cut the ground away
|
|
762
|
+
camera.near = Math.min(Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01), Math.max(1e-6, (distance - focusRadius) * 0.5));
|
|
763
|
+
clearGround(camera, focusPos);
|
|
723
764
|
camera.lookAt(target);
|
|
724
|
-
camera.near = Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01);
|
|
725
765
|
camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
|
|
726
766
|
}
|
|
727
767
|
if (ride && (ride.view === "follow" || ride.view === "above") && typeof ride.target !== "string") {
|
|
@@ -748,6 +788,8 @@ export function createSpaceItem(model, deps) {
|
|
|
748
788
|
if (k >= 1)
|
|
749
789
|
model.transition = null;
|
|
750
790
|
}
|
|
791
|
+
// never under the ground: a ride from a satellite that has come down, or a glide whose straight line runs through the Earth, is held 1 km above it, on its line from the centre
|
|
792
|
+
clearGround(camera, null);
|
|
751
793
|
camera.fov = fovNow;
|
|
752
794
|
camera.aspect = size.width / Math.max(1, size.height);
|
|
753
795
|
// the ground the picture spans straight below a ridden satellite, in kilometres: the height above the ground over the vertical field of view (flat-ground, to compare with a tile level's size)
|
|
@@ -871,6 +913,10 @@ export function createSpaceItem(model, deps) {
|
|
|
871
913
|
return t < 0 ? null : [eye.x + t * ray.x, eye.y + t * ray.y, eye.z + t * ray.z];
|
|
872
914
|
},
|
|
873
915
|
};
|
|
916
|
+
// the clouds give way as their texels grow past the map tiles' pixels, fragment by fragment: the tiles' radius is `focal / distance`, so a texel is `texelK / distance` pixels wide; `cloudShown` is the nearest ground's
|
|
917
|
+
model.cloudShown = cloudFade((focal / away) * model.ratio(), model.cloudFade);
|
|
918
|
+
cloudMaterial.uniforms["fadeGone"].value = model.cloudFade;
|
|
919
|
+
cloudMaterial.uniforms["texelK"].value = (2 * Math.PI * focal * model.ratio()) / CLOUD_WIDTH;
|
|
874
920
|
tiles.sync({ lon: 0, lat: 0, width: size.width, height: size.height, panX: 0, panY: 0, radius: focal / away, perspective: look }, [sunLocal.value.x, sunLocal.value.y, sunLocal.value.z], true, model.ratio());
|
|
875
921
|
deps.onTilesDrawn?.();
|
|
876
922
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.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",
|