@johnmorrisdotca/wakusei-planets 0.60.0 → 0.61.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.
@@ -0,0 +1,147 @@
1
+ import { toWorld } from "./drive.js";
2
+ import { MODEL_NODES, fromModelFrame, modelPose, rigOf } from "./rig.js";
3
+ /**
4
+ * Load a rover model from a GLB and read its rig. The nodes it must give are in `MODEL_NODES`: `wheel-xx` (rolled about X), `steer-xx` (turned about Y) and `eye` or `seat-commander`; a model with no corner wheel is refused.
5
+ * The loader and the meshopt decoder are three.js's own add-ons, imported when this is first called. Each call makes its own copy (the loaded file is read again from the browser's cache), which `dispose()` frees.
6
+ *
7
+ * @param url - Where the GLB is served from.
8
+ * @param options - `signal` to cancel the request.
9
+ * @returns The model, or a rejection when the file cannot be read or has no corner wheel.
10
+ *
11
+ * @example
12
+ * ```ts no-run
13
+ * import { loadVehicleModel } from "@johnmorrisdotca/wakusei-planets/surface/model";
14
+ *
15
+ * const model = await loadVehicleModel("https://johnmorrisdotca.github.io/wakusei-planets/models/perseverance.glb");
16
+ * console.log(model.rig.track.toFixed(2), "m between the wheels");
17
+ * ```
18
+ */
19
+ export async function loadVehicleModel(url, options = {}) {
20
+ const [three, { GLTFLoader }, { MeshoptDecoder }] = await Promise.all([import("three"), import("three/addons/loaders/GLTFLoader.js"), import("three/addons/libs/meshopt_decoder.module.js")]);
21
+ options.signal?.throwIfAborted();
22
+ const loader = new GLTFLoader();
23
+ loader.setMeshoptDecoder(MeshoptDecoder);
24
+ const gltf = await loader.loadAsync(url);
25
+ options.signal?.throwIfAborted();
26
+ return makeModel(three, gltf.scene);
27
+ }
28
+ function makeModel(T, root) {
29
+ root.matrixAutoUpdate = false;
30
+ root.updateMatrixWorld(true);
31
+ const found = new Map();
32
+ root.traverse((node) => {
33
+ if (node.name !== "" && !found.has(node.name))
34
+ found.set(node.name, node);
35
+ });
36
+ const names = [...MODEL_NODES.wheels, ...MODEL_NODES.steers, ...MODEL_NODES.eyes].filter((name) => found.has(name));
37
+ const at = {};
38
+ const here = new T.Vector3();
39
+ for (const name of names) {
40
+ found.get(name).getWorldPosition(here);
41
+ at[name] = fromModelFrame([here.x, here.y, here.z]);
42
+ }
43
+ const box = new T.Box3().setFromObject(root);
44
+ const size = box.getSize(new T.Vector3());
45
+ // a wheel's radius: half the height of the biggest wheel node
46
+ let wheelRadius = 0;
47
+ const wheelBox = new T.Box3();
48
+ for (const name of MODEL_NODES.wheels) {
49
+ const node = found.get(name);
50
+ if (node === undefined)
51
+ continue;
52
+ wheelBox.setFromObject(node);
53
+ wheelRadius = Math.max(wheelRadius, (wheelBox.max.y - wheelBox.min.y) / 2);
54
+ }
55
+ const nodes = { at, wheelRadius, length: size.z };
56
+ const rig = rigOf(nodes);
57
+ if (rig === undefined) {
58
+ disposeAll(root);
59
+ throw new Error("the model has no wheel-fl, wheel-fr, wheel-rl and wheel-rr nodes");
60
+ }
61
+ // the nodes that move, with the turn they were loaded with
62
+ const moving = new Map();
63
+ for (const name of [...MODEL_NODES.wheels, ...MODEL_NODES.steers]) {
64
+ const node = found.get(name);
65
+ if (node !== undefined)
66
+ moving.set(name, { node, base: node.quaternion.clone() });
67
+ }
68
+ root.traverse((node) => {
69
+ node.frustumCulled = false;
70
+ });
71
+ const scene = new T.Scene();
72
+ const sunLight = new T.DirectionalLight(0xffffff, 3);
73
+ const fill = new T.AmbientLight(0xffffff, 0.35);
74
+ scene.add(root, sunLight, fill, sunLight.target);
75
+ const camera = new T.Camera();
76
+ camera.matrixAutoUpdate = false;
77
+ const angles = {};
78
+ let renders = 0;
79
+ const [ax, ay] = [new T.Vector3(1, 0, 0), new T.Vector3(0, 1, 0)];
80
+ const turn = new T.Quaternion();
81
+ return {
82
+ rig,
83
+ nodes: names,
84
+ height: size.y,
85
+ angles,
86
+ get renders() {
87
+ return renders;
88
+ },
89
+ place(state, sun, strength) {
90
+ const pose = modelPose(state);
91
+ // a positive roll is forward (the top moving toward +Z, a turn about +X); the model's +X is the left, so a steer to the right is a turn about +Y the other way
92
+ for (const [name, entry] of moving) {
93
+ const roll = pose.roll[name];
94
+ const steer = pose.steer[name];
95
+ if (roll !== undefined) {
96
+ angles[name] = roll;
97
+ entry.node.quaternion.copy(entry.base).multiply(turn.setFromAxisAngle(ax, roll));
98
+ }
99
+ else if (steer !== undefined) {
100
+ angles[name] = -steer;
101
+ entry.node.quaternion.copy(entry.base).multiply(turn.setFromAxisAngle(ay, -steer));
102
+ }
103
+ entry.node.matrixWorldNeedsUpdate = true;
104
+ entry.node.updateMatrix();
105
+ }
106
+ // the model's frame in the scene's (x east, y up, z minus north): the drive frame's axes, with left and right swapped for the model's
107
+ const o = toWorld(state, [0, 0, 0]);
108
+ const axis = (v) => {
109
+ const p = toWorld(state, v);
110
+ return [p[0] - o[0], p[1] - o[1], -(p[2] - o[2])];
111
+ };
112
+ const [cx, cy, cz] = [axis([-1, 0, 0]), axis([0, 1, 0]), axis([0, 0, 1])];
113
+ root.matrix.set(cx[0], cy[0], cz[0], o[0], cx[1], cy[1], cz[1], o[1], cx[2], cy[2], cz[2], -o[2], 0, 0, 0, 1);
114
+ root.updateMatrixWorld(true);
115
+ sunLight.position.set(sun[0] * 100, sun[1] * 100, sun[2] * 100).add(here.set(o[0], o[1], -o[2]));
116
+ sunLight.target.position.set(o[0], o[1], -o[2]);
117
+ sunLight.target.updateMatrixWorld();
118
+ sunLight.intensity = 3 * strength;
119
+ },
120
+ render(gl, viewProjection) {
121
+ camera.projectionMatrix.fromArray(viewProjection);
122
+ camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
123
+ renders += 1;
124
+ const was = gl.autoClear;
125
+ gl.autoClear = false;
126
+ gl.render(scene, camera);
127
+ gl.autoClear = was;
128
+ },
129
+ dispose() {
130
+ disposeAll(root);
131
+ },
132
+ };
133
+ }
134
+ function disposeAll(root) {
135
+ root.traverse((node) => {
136
+ const mesh = node;
137
+ if (mesh.geometry === undefined)
138
+ return;
139
+ mesh.geometry.dispose();
140
+ for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) {
141
+ for (const value of Object.values(material))
142
+ if (value !== null && typeof value === "object" && "isTexture" in value)
143
+ value.dispose();
144
+ material.dispose();
145
+ }
146
+ });
147
+ }
@@ -0,0 +1,125 @@
1
+ import { type DriveState } from "./drive.ts";
2
+ import { type Part, type V3 } from "./shapes.ts";
3
+ /**
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
+ * 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.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { MODEL_NODES } from "@johnmorrisdotca/wakusei-planets/surface";
10
+ *
11
+ * console.log(MODEL_NODES.wheels.join(" "), MODEL_NODES.eyes.join(" or "));
12
+ * ```
13
+ */
14
+ export declare const MODEL_NODES: {
15
+ readonly wheels: readonly ["wheel-fl", "wheel-fr", "wheel-ml", "wheel-mr", "wheel-rl", "wheel-rr"];
16
+ readonly steers: readonly ["steer-fl", "steer-fr", "steer-rl", "steer-rr"];
17
+ readonly eyes: readonly ["eye", "seat-commander"];
18
+ };
19
+ /**
20
+ * The measures a drive step takes from a vehicle: where its four corner wheels touch the ground, how big they are and where the eyes are. `ROVER` is the lunar rover's; a model gives its own (`rigOf`).
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { ROVER, type Rig } from "@johnmorrisdotca/wakusei-planets/surface";
25
+ *
26
+ * const rig: Rig = ROVER;
27
+ * console.log(rig.wheels.length, rig.wheelRadius);
28
+ * ```
29
+ */
30
+ export interface Rig {
31
+ length: number;
32
+ wheelbase: number;
33
+ track: number;
34
+ wheelRadius: number;
35
+ /** The four corner wheels' centres in the vehicle's frame (x right, y up, z forward): front left, front right, rear left, rear right. */
36
+ wheels: readonly V3[];
37
+ /** The eyes of the view from the vehicle. */
38
+ seat: V3;
39
+ }
40
+ /**
41
+ * What the loader finds in a model: where each named node's origin is (in the drive frame, metres), the radius of the wheels and the length of the model along Z.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import type { ModelNodes } from "@johnmorrisdotca/wakusei-planets/surface";
46
+ *
47
+ * const nodes: ModelNodes = { at: { eye: [0, 1.9, 0] }, wheelRadius: 0.3, length: 2.4 };
48
+ * console.log(Object.keys(nodes.at).length, nodes.length);
49
+ * ```
50
+ */
51
+ export interface ModelNodes {
52
+ /** The world position of each named node that exists. */
53
+ at: Readonly<Record<string, V3>>;
54
+ /** The radius of the wheels, metres, from the biggest wheel's size (`0` when it could not be told). */
55
+ wheelRadius: number;
56
+ /** The model's length along Z, metres. */
57
+ length: number;
58
+ }
59
+ /**
60
+ * The rig of a model: its four corner wheels where its `wheel-fl`, `wheel-fr`, `wheel-rl` and `wheel-rr` nodes are, its wheelbase and track from them, its eyes where `eye` (or `seat-commander`) is. What a model does
61
+ * not say is the lunar rover's value; a model with no corner wheel at all is `undefined` (it cannot be driven by its wheels).
62
+ *
63
+ * @param nodes - What was found in the model.
64
+ * @returns The rig, or `undefined` when a corner wheel is missing.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import { rigOf } from "@johnmorrisdotca/wakusei-planets/surface";
69
+ *
70
+ * const rig = rigOf({ at: { "wheel-fl": [-1, 0.25, 1], "wheel-fr": [1, 0.25, 1], "wheel-rl": [-1, 0.25, -1], "wheel-rr": [1, 0.25, -1], eye: [0, 2, 0] }, wheelRadius: 0.25, length: 3 });
71
+ * console.log(rig?.wheelbase, rig?.track, rig?.seat);
72
+ * ```
73
+ */
74
+ export declare function rigOf(nodes: ModelNodes): Rig | undefined;
75
+ /**
76
+ * How far each named node of a rover model is turned for a drive state: the wheels' roll about X (the four corner wheels as `spin` has them, each middle wheel the mean of the two beside it) and the steering pivots'
77
+ * turn about Y (the front ones with the steer, the rear ones the other way, as the lunar rover's four wheels steer).
78
+ *
79
+ * @param state - The vehicle.
80
+ * @returns Radians for each node name: `roll` for the `wheel-xx` nodes about X, `steer` for the `steer-xx` nodes about Y.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { modelPose, startDrive } from "@johnmorrisdotca/wakusei-planets/surface";
85
+ *
86
+ * const rover = { ...startDrive(0, 0, 0, 0), steer: 0.2, spin: [1, 1, 3, 3] };
87
+ * const pose = modelPose(rover);
88
+ * console.log(pose.roll["wheel-ml"], pose.steer["steer-fl"], pose.steer["steer-rr"]);
89
+ * ```
90
+ */
91
+ export declare function modelPose(state: Pick<DriveState, "spin" | "steer">): {
92
+ roll: Record<string, number>;
93
+ steer: Record<string, number>;
94
+ };
95
+ /**
96
+ * Where a model's glTF frame (+Y up, front +Z, the left on +X) puts a point of the model in the drive frame (x right, y up, z forward): the left and right swapped.
97
+ *
98
+ * @param p - A point in the model's metres.
99
+ * @returns The point in the drive frame.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { fromModelFrame } from "@johnmorrisdotca/wakusei-planets/surface";
104
+ *
105
+ * console.log(fromModelFrame([0.5, 1.2, 2]));
106
+ * ```
107
+ */
108
+ export declare const fromModelFrame: (p: readonly [number, number, number]) => V3;
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).
111
+ *
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`.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { modelShadowParts, partShadows, startDrive, ROVER } from "@johnmorrisdotca/wakusei-planets/surface";
120
+ *
121
+ * const parts = modelShadowParts(startDrive(0, 0, 0, 0), ROVER, 1.5);
122
+ * console.log(partShadows(parts, 0, 90, 20).length / 9, "triangles of shadow");
123
+ * ```
124
+ */
125
+ export declare function modelShadowParts(state: Pick<DriveState, "east" | "north" | "heading" | "pitch" | "roll" | "y">, rig: Rig, height: number): Part[];
@@ -0,0 +1,107 @@
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
+ // 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
+ import { ROVER, toWorld } from "./drive.js";
4
+ import { box } from "./shapes.js";
5
+ /**
6
+ * 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
+ * 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.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { MODEL_NODES } from "@johnmorrisdotca/wakusei-planets/surface";
12
+ *
13
+ * console.log(MODEL_NODES.wheels.join(" "), MODEL_NODES.eyes.join(" or "));
14
+ * ```
15
+ */
16
+ export const MODEL_NODES = {
17
+ wheels: ["wheel-fl", "wheel-fr", "wheel-ml", "wheel-mr", "wheel-rl", "wheel-rr"],
18
+ steers: ["steer-fl", "steer-fr", "steer-rl", "steer-rr"],
19
+ eyes: ["eye", "seat-commander"],
20
+ };
21
+ /**
22
+ * The rig of a model: its four corner wheels where its `wheel-fl`, `wheel-fr`, `wheel-rl` and `wheel-rr` nodes are, its wheelbase and track from them, its eyes where `eye` (or `seat-commander`) is. What a model does
23
+ * not say is the lunar rover's value; a model with no corner wheel at all is `undefined` (it cannot be driven by its wheels).
24
+ *
25
+ * @param nodes - What was found in the model.
26
+ * @returns The rig, or `undefined` when a corner wheel is missing.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { rigOf } from "@johnmorrisdotca/wakusei-planets/surface";
31
+ *
32
+ * const rig = rigOf({ at: { "wheel-fl": [-1, 0.25, 1], "wheel-fr": [1, 0.25, 1], "wheel-rl": [-1, 0.25, -1], "wheel-rr": [1, 0.25, -1], eye: [0, 2, 0] }, wheelRadius: 0.25, length: 3 });
33
+ * console.log(rig?.wheelbase, rig?.track, rig?.seat);
34
+ * ```
35
+ */
36
+ export function rigOf(nodes) {
37
+ const [fl, fr, rl, rr] = ["wheel-fl", "wheel-fr", "wheel-rl", "wheel-rr"].map((name) => nodes.at[name]);
38
+ if (fl === undefined || fr === undefined || rl === undefined || rr === undefined)
39
+ return undefined;
40
+ const eye = nodes.at["eye"] ?? nodes.at["seat-commander"] ?? ROVER.seat;
41
+ const wheelbase = Math.abs((fl[2] + fr[2]) / 2 - (rl[2] + rr[2]) / 2);
42
+ const track = Math.abs((fr[0] + rr[0]) / 2 - (fl[0] + rl[0]) / 2);
43
+ const radius = nodes.wheelRadius > 0 ? nodes.wheelRadius : Math.max(0.05, (fl[1] + fr[1] + rl[1] + rr[1]) / 4);
44
+ return { length: nodes.length > 0 ? nodes.length : wheelbase + 2 * radius, wheelbase, track, wheelRadius: radius, wheels: [fl, fr, rl, rr], seat: eye };
45
+ }
46
+ /**
47
+ * How far each named node of a rover model is turned for a drive state: the wheels' roll about X (the four corner wheels as `spin` has them, each middle wheel the mean of the two beside it) and the steering pivots'
48
+ * turn about Y (the front ones with the steer, the rear ones the other way, as the lunar rover's four wheels steer).
49
+ *
50
+ * @param state - The vehicle.
51
+ * @returns Radians for each node name: `roll` for the `wheel-xx` nodes about X, `steer` for the `steer-xx` nodes about Y.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { modelPose, startDrive } from "@johnmorrisdotca/wakusei-planets/surface";
56
+ *
57
+ * const rover = { ...startDrive(0, 0, 0, 0), steer: 0.2, spin: [1, 1, 3, 3] };
58
+ * const pose = modelPose(rover);
59
+ * console.log(pose.roll["wheel-ml"], pose.steer["steer-fl"], pose.steer["steer-rr"]);
60
+ * ```
61
+ */
62
+ export function modelPose(state) {
63
+ const [fl, fr, rl, rr] = state.spin;
64
+ return {
65
+ roll: { "wheel-fl": fl, "wheel-fr": fr, "wheel-ml": (fl + rl) / 2, "wheel-mr": (fr + rr) / 2, "wheel-rl": rl, "wheel-rr": rr },
66
+ steer: { "steer-fl": state.steer, "steer-fr": state.steer, "steer-rl": -state.steer, "steer-rr": -state.steer },
67
+ };
68
+ }
69
+ /**
70
+ * Where a model's glTF frame (+Y up, front +Z, the left on +X) puts a point of the model in the drive frame (x right, y up, z forward): the left and right swapped.
71
+ *
72
+ * @param p - A point in the model's metres.
73
+ * @returns The point in the drive frame.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * import { fromModelFrame } from "@johnmorrisdotca/wakusei-planets/surface";
78
+ *
79
+ * console.log(fromModelFrame([0.5, 1.2, 2]));
80
+ * ```
81
+ */
82
+ export const fromModelFrame = (p) => [-p[0], p[1], p[2]];
83
+ /**
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).
85
+ *
86
+ * @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`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { modelShadowParts, partShadows, startDrive, ROVER } from "@johnmorrisdotca/wakusei-planets/surface";
94
+ *
95
+ * const parts = modelShadowParts(startDrive(0, 0, 0, 0), ROVER, 1.5);
96
+ * console.log(partShadows(parts, 0, 90, 20).length / 9, "triangles of shadow");
97
+ * ```
98
+ */
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]);
105
+ }
106
+ return [{ ...part, position, normal: part.normal }];
107
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Item3D, Scene3D } from "@johnmorrisdotca/kazoku-ui/renderer";
2
2
  import type { ThreeParts } from "../scene/body.ts";
3
3
  import { type DriveState } from "./drive.ts";
4
+ import type { VehicleModel } from "./model.ts";
4
5
  import { type SiteObject } from "./objects.ts";
5
6
  import type { HeightLevel, TerrainManifest } from "./height.ts";
6
7
  import type { MoonSky } from "./sky.ts";
@@ -29,6 +30,8 @@ export interface SurfaceState {
29
30
  scale?: number;
30
31
  /** The rover being driven, as `driveStep` leaves it: drawn in place of the one standing at its published place. */
31
32
  vehicle?: DriveState;
33
+ /** A loaded rover model (`loadVehicleModel`): drawn in place of the shapes of the rover being driven, with its own materials, over the ground. */
34
+ model?: VehicleModel;
32
35
  /** The path the driven rover has left, east, north, east, north, ... in metres: drawn as tracks. */
33
36
  trail?: readonly number[];
34
37
  /** The lunar module coming down (Apollo 17's descent): where it is, how high over the ground under it, which way it flies and the share of full thrust; drawn whole, with its plume, in place of the one standing at its place. */
@@ -1,6 +1,7 @@
1
1
  import { rocksAround } from "./detail.js";
2
2
  import { DISC_FRAGMENT, DISC_VERTEX, GROUND_FRAGMENT, GROUND_VERTEX, OBJECT_FRAGMENT, OBJECT_VERTEX, ROCK_FRAGMENT, ROCK_VERTEX, SHADOW_FRAGMENT, SHADOW_VERTEX, TRACK_FRAGMENT, TRACK_VERTEX, DUST_FRAGMENT, DUST_VERTEX, PLUME_FRAGMENT, PLUME_VERTEX } from "./glsl.js";
3
3
  import { driveParts } from "./drive.js";
4
+ import { modelShadowParts } from "./rig.js";
4
5
  import { placePart, ascentParts, landerParts } from "./shapes.js";
5
6
  import { KEEP_OUT, objectParts, partShadows } from "./objects.js";
6
7
  import { rockMesh } from "./rocks.js";
@@ -345,15 +346,28 @@ export function createSurfaceItem(options) {
345
346
  let vehicleMesh;
346
347
  let vehicleShadow;
347
348
  let vehicleCount = 0;
349
+ let modelDrawn;
348
350
  const makeVehicle = (state) => {
349
351
  const v = state.vehicle;
350
352
  if (v === undefined || state.objects === false) {
353
+ modelDrawn = undefined;
351
354
  if (vehicleMesh !== undefined)
352
355
  vehicleMesh.visible = false;
353
356
  if (vehicleShadow !== undefined)
354
357
  vehicleShadow.visible = false;
355
358
  return;
356
359
  }
360
+ if (state.model !== undefined) {
361
+ // 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
362
+ if (vehicleMesh !== undefined)
363
+ vehicleMesh.visible = false;
364
+ const sun = state.sky.sun;
365
+ state.model.place(v, [sun.enu[0], sun.enu[2], -sun.enu[1]], Math.max(0, Math.min(1, sun.altitude / 8)));
366
+ modelDrawn = state.model;
367
+ makeVehicleShadow(state, modelShadowParts(v, state.model.rig, state.model.height));
368
+ return;
369
+ }
370
+ modelDrawn = undefined;
357
371
  const parts = driveParts(v);
358
372
  const count = parts.reduce((n, part) => n + part.position.length / 3, 0);
359
373
  if (vehicleMesh === undefined || count !== vehicleCount) {
@@ -394,6 +408,10 @@ export function createSurfaceItem(options) {
394
408
  position.needsUpdate = true;
395
409
  normal.needsUpdate = true;
396
410
  vehicleMesh.visible = true;
411
+ makeVehicleShadow(state, parts);
412
+ };
413
+ const makeVehicleShadow = (state, parts) => {
414
+ const v = state.vehicle;
397
415
  const shadow = state.shadows === false ? [] : partShadows(parts, v.y, state.sky.sun.azimuth, state.sky.sun.altitude);
398
416
  const geometry = new T.BufferGeometry();
399
417
  geometry.setAttribute("position", new T.BufferAttribute(new Float32Array(shadow), 3));
@@ -715,11 +733,14 @@ export function createSurfaceItem(options) {
715
733
  target.setSize(w, h);
716
734
  three.setRenderTarget(target);
717
735
  gl.render(scene, camera);
736
+ modelDrawn?.render(gl, uniforms.uVP.value);
718
737
  three.setRenderTarget(null);
719
738
  gl.render(blitScene, camera);
720
739
  }
721
- else
740
+ else {
722
741
  gl.render(scene, camera);
742
+ modelDrawn?.render(gl, uniforms.uVP.value);
743
+ }
723
744
  if (measuring) {
724
745
  const canvas = gl.domElement;
725
746
  // reading one pixel back waits for the card to finish the draw (`finish` returns at once in a browser that draws in another process)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.60.0",
3
+ "version": "0.61.0",
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",
@@ -19,6 +19,9 @@
19
19
  "neptune",
20
20
  "pluto",
21
21
  "dwarf-planets",
22
+ "asteroids",
23
+ "comets",
24
+ "stars",
22
25
  "astronomy",
23
26
  "ephemeris",
24
27
  "heliocentric",
@@ -93,6 +96,7 @@
93
96
  "./dist/space/element.js",
94
97
  "./dist/plan/element.js",
95
98
  "./dist/flat/define.js",
99
+ "./dist/flat/system-define.js",
96
100
  "./dist/surface/element.js",
97
101
  "./dist/surface/land.js",
98
102
  "./dist/earth-places.js",
@@ -105,6 +109,7 @@
105
109
  "./src/space/element.ts",
106
110
  "./src/plan/element.ts",
107
111
  "./src/flat/define.ts",
112
+ "./src/flat/system-define.ts",
108
113
  "./src/surface/element.ts",
109
114
  "./src/surface/land.ts",
110
115
  "./src/earth-places.ts",
@@ -166,6 +171,16 @@
166
171
  "import": "./dist/flat/define.js",
167
172
  "default": "./dist/flat/define.js"
168
173
  },
174
+ "./flat/system": {
175
+ "types": "./dist/flat/system.d.ts",
176
+ "import": "./dist/flat/system.js",
177
+ "default": "./dist/flat/system.js"
178
+ },
179
+ "./flat/system/define": {
180
+ "types": "./dist/flat/system-define.d.ts",
181
+ "import": "./dist/flat/system-define.js",
182
+ "default": "./dist/flat/system-define.js"
183
+ },
169
184
  "./surface": {
170
185
  "types": "./dist/surface/index.d.ts",
171
186
  "import": "./dist/surface/index.js",
@@ -176,6 +191,11 @@
176
191
  "import": "./dist/surface/element.js",
177
192
  "default": "./dist/surface/element.js"
178
193
  },
194
+ "./surface/model": {
195
+ "types": "./dist/surface/model.d.ts",
196
+ "import": "./dist/surface/model.js",
197
+ "default": "./dist/surface/model.js"
198
+ },
179
199
  "./surface/land": {
180
200
  "types": "./dist/surface/land.d.ts",
181
201
  "import": "./dist/surface/land.js",
@@ -620,8 +640,12 @@
620
640
  "lint": "eslint .",
621
641
  "typecheck": "tsc -p tsconfig.check.json && tsc -p tsconfig.tools.json && tsc -p tsconfig.demo.json",
622
642
  "test": "node --test test/*.test.ts",
643
+ "test:coverage": "node --test --experimental-test-coverage --test-coverage-include='src/**' --test-coverage-lines=96 --test-coverage-branches=93 --test-coverage-functions=95 test/*.test.ts",
644
+ "size:budget": "node scripts/check-size.mjs",
645
+ "size:budget:update": "node scripts/check-size.mjs --write",
646
+ "api:update": "node scripts/api-surface.mjs --write",
623
647
  "test:package": "pnpm build && node scripts/check-package.ts",
624
- "check": "pnpm lint && pnpm typecheck && pnpm test && pnpm build && node scripts/check-package.ts",
648
+ "check": "pnpm lint && pnpm typecheck && pnpm test:coverage && pnpm build && node scripts/check-package.ts && pnpm size:budget",
625
649
  "prepublishOnly": "pnpm check",
626
650
  "tiles": ".cache/venv/bin/python -I scripts/make-body-tiles.py build",
627
651
  "tiles:moon": ".cache/venv/bin/python -I scripts/make-body-tiles.py sharp --bodies moon",