@johnmorrisdotca/wakusei-planets 0.73.0 → 0.74.1

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.
@@ -21,6 +21,7 @@ const TEMPLATE = `<style>
21
21
  :host([data-dragging]) { cursor: grabbing; }
22
22
  #stage { position: absolute; inset: 0; }
23
23
  #note { position: absolute; left: 8px; right: 8px; bottom: 6px; margin: 0; font: 400 11px/1.35 system-ui, sans-serif; color: #c8ccd4; text-shadow: 0 1px 2px #000; pointer-events: none; }
24
+ @media (max-width: 520px) { :host([line-below]) #note { display: none; } }
24
25
  #status { position: absolute; inset: 0; display: grid; place-items: center; font: 500 13px system-ui, sans-serif; color: #c8ccd4; pointer-events: none; }
25
26
  #status[hidden] { display: none; }
26
27
  #labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
@@ -469,7 +470,7 @@ export class WakuseiSurface extends HTMLElement {
469
470
  if (m === undefined)
470
471
  return "";
471
472
  if (this.#site()?.ground === "flat")
472
- return this.#lang() === "ja" ? "地面: 高さのデータが追加されるまでの平らな代用です。ここには、実測した起伏も作った起伏もありません。太陽、空、重力は、この場所と時刻の実際のとおりです。" : "Ground: flat stand-in until a DTM is added. There is no relief here, measured or made. The Sun, sky and gravity are the real ones for this place and time.";
473
+ return this.#lang() === "ja" ? "ここの地面は、高さのデータが追加されるまでの平らな代用です。実測した起伏はありません。" : "The ground here is a flat stand-in until height data is added. Nothing on it is measured.";
473
474
  const made = this.#noDetail() ? "" : this.#lang() === "ja" ? "5 m より細かい地形(小さなクレーター、砂塵、岩)は計算で作ったもので、実測ではありません。" : "Detail finer than the 5 m grid (small craters, dust, rocks) is made, not measured.";
474
475
  const things = this.#objects.length === 0 ? "" : this.#lang() === "ja" ? " 地面の物は、公表された座標の位置にこのパッケージが置いたもので、形は簡単な絵です。" : " The things on the ground are placed by this package at published positions, as plain drawings.";
475
476
  const credit = joinCredits(m.credit, m.picture?.credit);
@@ -39,7 +39,7 @@ export function flatManifest(site) {
39
39
  picture: null,
40
40
  horizon: null,
41
41
  credit: "no height model for this site yet",
42
- accuracy: "ground: flat stand-in until a DTM is added; there is no relief here, measured or made",
42
+ accuracy: "ground: flat stand-in until height data is added; nothing on it is measured",
43
43
  };
44
44
  }
45
45
  /**
@@ -1,4 +1,5 @@
1
1
  import { type DriveState } from "./drive.ts";
2
+ import type { V3 } from "./shapes.ts";
2
3
  import { type Rig } from "./rig.ts";
3
4
  /**
4
5
  * A rover model that has been loaded: its rig for the drive step and the calls the scene makes. Made by `loadVehicleModel`.
@@ -19,6 +20,8 @@ export interface VehicleModel {
19
20
  readonly nodes: readonly string[];
20
21
  /** The model's height over the ground, metres. */
21
22
  readonly height: number;
23
+ /** Triangles of each mesh, in the drive frame at rest. Each casts on its own, so the shadow follows the rover. */
24
+ readonly shadowClouds: readonly (readonly V3[])[];
22
25
  /** Put the model where the drive state is, with the wheels rolled and steered, lit from `sun` (a direction in the scene's frame, east, up, minus north) at `strength` (0 to 1). */
23
26
  place(state: DriveState, sun: readonly [number, number, number], strength: number): void;
24
27
  /** Draw it with the page's renderer over what is drawn, with the ground's view-projection matrix. */
@@ -78,10 +78,12 @@ function makeModel(T, root) {
78
78
  let renders = 0;
79
79
  const [ax, ay] = [new T.Vector3(1, 0, 0), new T.Vector3(0, 1, 0)];
80
80
  const turn = new T.Quaternion();
81
+ const shadowClouds = shadowCloudsOf(T, root);
81
82
  return {
82
83
  rig,
83
84
  nodes: names,
84
85
  height: size.y,
86
+ shadowClouds,
85
87
  angles,
86
88
  get renders() {
87
89
  return renders;
@@ -131,6 +133,52 @@ function makeModel(T, root) {
131
133
  },
132
134
  };
133
135
  }
136
+ /**
137
+ * Triangles of each mesh, strided so a dense file stays a few hundred. One hull of a whole mesh is the body's box, which is the slab. A triangle casts on its own.
138
+ */
139
+ function shadowCloudsOf(T, root) {
140
+ root.updateMatrixWorld(true);
141
+ const v = new T.Vector3();
142
+ const clouds = [];
143
+ const cap = 500;
144
+ root.traverse((node) => {
145
+ const mesh = node;
146
+ if (mesh.isMesh !== true)
147
+ return;
148
+ const geom = mesh.geometry;
149
+ const attr = geom?.getAttribute?.("position");
150
+ if (attr === undefined || attr.count < 3)
151
+ return;
152
+ const index = geom.getIndex?.() ?? null;
153
+ const triCount = index === null ? Math.floor(attr.count / 3) : Math.floor(index.count / 3);
154
+ if (triCount < 1)
155
+ return;
156
+ const step = Math.max(1, Math.ceil(triCount / cap));
157
+ const at = (i) => {
158
+ v.fromBufferAttribute(attr, i).applyMatrix4(mesh.matrixWorld);
159
+ return fromModelFrame([v.x, v.y, v.z]);
160
+ };
161
+ for (let t = 0; t < triCount; t += step) {
162
+ const base = t * 3;
163
+ const pa = at(index === null ? base : index.getX(base));
164
+ const pb = at(index === null ? base + 1 : index.getX(base + 1));
165
+ const pc = at(index === null ? base + 2 : index.getX(base + 2));
166
+ const abx = pb[0] - pa[0];
167
+ const aby = pb[1] - pa[1];
168
+ const abz = pb[2] - pa[2];
169
+ const acx = pc[0] - pa[0];
170
+ const acy = pc[1] - pa[1];
171
+ const acz = pc[2] - pa[2];
172
+ const cx = aby * acz - abz * acy;
173
+ const cy = abz * acx - abx * acz;
174
+ const cz = abx * acy - aby * acx;
175
+ if (cx * cx + cy * cy + cz * cz < 1e-6)
176
+ continue;
177
+ clouds.push([pa, pb, pc]);
178
+ }
179
+ });
180
+ return clouds;
181
+ }
134
182
  function disposeAll(root) {
135
183
  root.traverse((node) => {
136
184
  const mesh = node;
@@ -1,5 +1,5 @@
1
1
  import { type DriveState } from "./drive.ts";
2
- import { type Part, type V3 } from "./shapes.ts";
2
+ import type { Part, V3 } from "./shapes.ts";
3
3
  /**
4
4
  * The nodes a rover model may name: `wheel-fl`, `wheel-fr`, `wheel-ml`, `wheel-mr`, `wheel-rl` and `wheel-rr` roll about X (their origin is the wheel's centre), `steer-fl`, `steer-fr`, `steer-rl` and `steer-rr`
5
5
  * turn about Y (a pivot holding the wheel and its leg), and the eye is `eye`, or `seat-commander` (the left seat) when the model has no `eye`. The model's metres have +Y up and its front on +Z.
@@ -107,19 +107,18 @@ export declare function modelPose(state: Pick<DriveState, "spin" | "steer">): {
107
107
  */
108
108
  export declare const fromModelFrame: (p: readonly [number, number, number]) => V3;
109
109
  /**
110
- * The shadow of a model: one box the size of its body, placed as the drive state puts the vehicle (a shadow is the hull of a part's corners, so a box is its footprint).
110
+ * The shadow of a model: the points of its meshes, placed as the drive state puts the vehicle. One cloud is one mesh, in the drive frame at rest (x right, y up, z forward). `partShadows` takes the hull of each cloud, so the shadow follows the rover.
111
111
  *
112
112
  * @param state - The vehicle.
113
- * @param rig - The model's rig.
114
- * @param height - The model's height over the ground, metres.
115
- * @returns One part, to hand to `partShadows`.
113
+ * @param clouds - The meshes' points, as `VehicleModel.shadowClouds` keeps them.
114
+ * @returns One part a mesh, to hand to `partShadows`.
116
115
  *
117
116
  * @example
118
117
  * ```ts
119
- * import { modelShadowParts, partShadows, startDrive, ROVER } from "@johnmorrisdotca/wakusei-planets/surface";
118
+ * import { modelShadowParts, partShadows, startDrive } from "@johnmorrisdotca/wakusei-planets/surface";
120
119
  *
121
- * const parts = modelShadowParts(startDrive(0, 0, 0, 0), ROVER, 1.5);
120
+ * const parts = modelShadowParts(startDrive(0, 0, 0, 0), [[[-0.4, 0.5, 0.8], [0.4, 0.5, 0.8], [0, 1.2, 0]]]);
122
121
  * console.log(partShadows(parts, 0, 90, 20).length / 9, "triangles of shadow");
123
122
  * ```
124
123
  */
125
- export declare function modelShadowParts(state: Pick<DriveState, "east" | "north" | "heading" | "pitch" | "roll" | "y">, rig: Rig, height: number): Part[];
124
+ export declare function modelShadowParts(state: Pick<DriveState, "east" | "north" | "heading" | "pitch" | "roll" | "y">, clouds: readonly (readonly V3[])[]): Part[];
@@ -1,7 +1,6 @@
1
1
  // A rover model's rig, without a DOM and without three.js: the names of the nodes a model (a GLB) must give, the measures a drive step needs read from where those nodes are, and the angles the wheels and
2
2
  // steering pivots are turned to for a drive state. The loader (`model.ts`) finds the nodes; this decides what the numbers mean, so it is tested in node.
3
3
  import { ROVER, toWorld } from "./drive.js";
4
- import { box } from "./shapes.js";
5
4
  /**
6
5
  * The nodes a rover model may name: `wheel-fl`, `wheel-fr`, `wheel-ml`, `wheel-mr`, `wheel-rl` and `wheel-rr` roll about X (their origin is the wheel's centre), `steer-fl`, `steer-fr`, `steer-rl` and `steer-rr`
7
6
  * turn about Y (a pivot holding the wheel and its leg), and the eye is `eye`, or `seat-commander` (the left seat) when the model has no `eye`. The model's metres have +Y up and its front on +Z.
@@ -81,27 +80,31 @@ export function modelPose(state) {
81
80
  */
82
81
  export const fromModelFrame = (p) => [-p[0], p[1], p[2]];
83
82
  /**
84
- * The shadow of a model: one box the size of its body, placed as the drive state puts the vehicle (a shadow is the hull of a part's corners, so a box is its footprint).
83
+ * The shadow of a model: the points of its meshes, placed as the drive state puts the vehicle. One cloud is one mesh, in the drive frame at rest (x right, y up, z forward). `partShadows` takes the hull of each cloud, so the shadow follows the rover.
85
84
  *
86
85
  * @param state - The vehicle.
87
- * @param rig - The model's rig.
88
- * @param height - The model's height over the ground, metres.
89
- * @returns One part, to hand to `partShadows`.
86
+ * @param clouds - The meshes' points, as `VehicleModel.shadowClouds` keeps them.
87
+ * @returns One part a mesh, to hand to `partShadows`.
90
88
  *
91
89
  * @example
92
90
  * ```ts
93
- * import { modelShadowParts, partShadows, startDrive, ROVER } from "@johnmorrisdotca/wakusei-planets/surface";
91
+ * import { modelShadowParts, partShadows, startDrive } from "@johnmorrisdotca/wakusei-planets/surface";
94
92
  *
95
- * const parts = modelShadowParts(startDrive(0, 0, 0, 0), ROVER, 1.5);
93
+ * const parts = modelShadowParts(startDrive(0, 0, 0, 0), [[[-0.4, 0.5, 0.8], [0.4, 0.5, 0.8], [0, 1.2, 0]]]);
96
94
  * console.log(partShadows(parts, 0, 90, 20).length / 9, "triangles of shadow");
97
95
  * ```
98
96
  */
99
- export function modelShadowParts(state, rig, height) {
100
- const part = box([0, height / 2 + rig.wheelRadius, 0], [rig.track * 0.8, height, rig.length * 0.85], 0, 1);
101
- const position = [];
102
- for (let i = 0; i < part.position.length; i += 3) {
103
- const w = toWorld(state, [part.position[i], part.position[i + 1], part.position[i + 2]]);
104
- position.push(w[0], w[1], w[2]);
97
+ export function modelShadowParts(state, clouds) {
98
+ const out = [];
99
+ for (const cloud of clouds) {
100
+ if (cloud.length < 3)
101
+ continue;
102
+ const position = [];
103
+ for (const p of cloud) {
104
+ const w = toWorld(state, [p[0], p[1], p[2]]);
105
+ position.push(w[0], w[1], w[2]);
106
+ }
107
+ out.push({ position, normal: [], tone: 1 });
105
108
  }
106
- return [{ ...part, position, normal: part.normal }];
109
+ return out;
107
110
  }
@@ -379,13 +379,13 @@ export function createSurfaceItem(options) {
379
379
  return;
380
380
  }
381
381
  if (state.model !== undefined) {
382
- // a model draws itself (in its own pass, after the ground); the shapes are hidden and its shadow is a box the size of its body
382
+ // a model draws itself (in its own pass, after the ground); the shapes are hidden and its shadow follows the points of its meshes
383
383
  if (vehicleMesh !== undefined)
384
384
  vehicleMesh.visible = false;
385
385
  const sun = state.sky.sun;
386
386
  state.model.place(v, [sun.enu[0], sun.enu[2], -sun.enu[1]], Math.max(0, Math.min(1, sun.altitude / 8)));
387
387
  modelDrawn = state.model;
388
- makeVehicleShadow(state, modelShadowParts(v, state.model.rig, state.model.height));
388
+ makeVehicleShadow(state, modelShadowParts(v, state.model.shadowClouds));
389
389
  return;
390
390
  }
391
391
  modelDrawn = undefined;
@@ -715,7 +715,7 @@ export function createSurfaceItem(options) {
715
715
  earth.uniforms.uHalf.value = Math.tan((sky.earthDiameter * Math.PI) / 360);
716
716
  sun.uniforms.uHalf.value = Math.tan((sky.sunDiameter * Math.PI) / 360);
717
717
  sun.mesh.visible = sky.sun.altitude > -1;
718
- earth.mesh.visible = sky.earthDisc !== false && sky.earth.altitude > -1;
718
+ earth.mesh.visible = sky.earthDisc !== false && sky.earth.altitude > 0;
719
719
  skyMesh.visible = air !== null;
720
720
  if (air !== null) {
721
721
  const e = toEnu(axes.forward);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.73.0";
1
+ export declare const VERSION = "0.74.1";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The published package version. Snippets and texture addresses name it. test/version.test.ts keeps it equal to package.json.
2
- export const VERSION = "0.73.0";
2
+ export const VERSION = "0.74.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.73.0",
3
+ "version": "0.74.1",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",
@@ -1034,6 +1034,9 @@
1034
1034
  "pnpm": {
1035
1035
  "onlyBuiltDependencies": [
1036
1036
  "esbuild"
1037
- ]
1037
+ ],
1038
+ "patchedDependencies": {
1039
+ "@johnmorrisdotca/kazoku-ui@0.41.0": "patches/@johnmorrisdotca__kazoku-ui@0.41.0.patch"
1040
+ }
1038
1041
  }
1039
1042
  }