@johnmorrisdotca/wakusei-planets 0.47.0 → 0.49.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.
@@ -1,5 +1,6 @@
1
1
  import { rocksAround } from "./detail.js";
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 } from "./glsl.js";
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 } from "./glsl.js";
3
+ import { driveParts } from "./drive.js";
3
4
  import { KEEP_OUT, objectParts, partShadows } from "./objects.js";
4
5
  import { rockMesh } from "./rocks.js";
5
6
  import { cameraAxes, viewProjection } from "./view.js";
@@ -226,6 +227,7 @@ export function createSurfaceItem(options) {
226
227
  const list = options.objects ?? [];
227
228
  const ground = options.groundY;
228
229
  const on = state.objects !== false && list.length > 0 && ground !== undefined;
230
+ const driving = state.vehicle !== undefined;
229
231
  if (objectMesh !== undefined)
230
232
  objectMesh.visible = on;
231
233
  if (objectShadowMesh !== undefined)
@@ -234,7 +236,7 @@ export function createSurfaceItem(options) {
234
236
  trackMesh.visible = on;
235
237
  if (!on || ground === undefined)
236
238
  return;
237
- const key = `${state.sky.sun.azimuth.toFixed(1)}|${state.sky.sun.altitude.toFixed(1)}|${objectVersion}`;
239
+ const key = `${state.sky.sun.azimuth.toFixed(1)}|${state.sky.sun.altitude.toFixed(1)}|${objectVersion}|${driving}|${state.shadows !== false}`;
238
240
  if (key === objectKey)
239
241
  return;
240
242
  objectKey = key;
@@ -244,6 +246,8 @@ export function createSurfaceItem(options) {
244
246
  const tint = [];
245
247
  const shadow = [];
246
248
  for (const object of list) {
249
+ if (driving && object.kind === "rover")
250
+ continue;
247
251
  const base = ground(object.east, object.north);
248
252
  const parts = objectParts(object, base);
249
253
  for (const part of parts) {
@@ -254,7 +258,8 @@ export function createSurfaceItem(options) {
254
258
  tint.push(...(part.colour ?? [1, 1, 1]));
255
259
  }
256
260
  }
257
- shadow.push(...partShadows(parts, base, state.sky.sun.azimuth, state.sky.sun.altitude));
261
+ if (state.shadows !== false)
262
+ shadow.push(...partShadows(parts, base, state.sky.sun.azimuth, state.sky.sun.altitude));
258
263
  }
259
264
  const geometry = new T.BufferGeometry();
260
265
  geometry.setAttribute("position", new T.BufferAttribute(new Float32Array(position), 3));
@@ -333,6 +338,176 @@ export function createSurfaceItem(options) {
333
338
  trackMesh.renderOrder = 0.5;
334
339
  scene.add(trackMesh);
335
340
  }
341
+ // the rover being driven: its parts as one mesh turned and placed at each draw (a few thousand corners: cheap), its shadow, the path it has left as tracks and the grains it throws as small squares
342
+ let vehicleMesh;
343
+ let vehicleShadow;
344
+ let vehicleCount = 0;
345
+ const makeVehicle = (state) => {
346
+ const v = state.vehicle;
347
+ if (v === undefined || state.objects === false) {
348
+ if (vehicleMesh !== undefined)
349
+ vehicleMesh.visible = false;
350
+ if (vehicleShadow !== undefined)
351
+ vehicleShadow.visible = false;
352
+ return;
353
+ }
354
+ const parts = driveParts(v);
355
+ const count = parts.reduce((n, part) => n + part.position.length / 3, 0);
356
+ if (vehicleMesh === undefined || count !== vehicleCount) {
357
+ vehicleMesh?.geometry.dispose();
358
+ const geometry = new T.BufferGeometry();
359
+ geometry.setAttribute("position", new T.BufferAttribute(new Float32Array(count * 3), 3));
360
+ geometry.setAttribute("normal", new T.BufferAttribute(new Float32Array(count * 3), 3));
361
+ const tone = new Float32Array(count);
362
+ const tint = new Float32Array(count * 3);
363
+ let at = 0;
364
+ for (const part of parts) {
365
+ for (let i = 0; i < part.position.length / 3; i += 1) {
366
+ tone[at] = part.tone;
367
+ tint.set(part.colour ?? [1, 1, 1], at * 3);
368
+ at += 1;
369
+ }
370
+ }
371
+ geometry.setAttribute("tone", new T.BufferAttribute(tone, 1));
372
+ geometry.setAttribute("tint", new T.BufferAttribute(tint, 3));
373
+ vehicleCount = count;
374
+ if (vehicleMesh === undefined) {
375
+ vehicleMesh = new T.Mesh(geometry, objectMaterial);
376
+ vehicleMesh.frustumCulled = false;
377
+ vehicleMesh.renderOrder = 1;
378
+ scene.add(vehicleMesh);
379
+ }
380
+ else
381
+ vehicleMesh.geometry = geometry;
382
+ }
383
+ const position = vehicleMesh.geometry.getAttribute("position");
384
+ const normal = vehicleMesh.geometry.getAttribute("normal");
385
+ let at = 0;
386
+ for (const part of parts) {
387
+ position.array.set(part.position, at * 3);
388
+ normal.array.set(part.normal, at * 3);
389
+ at += part.position.length / 3;
390
+ }
391
+ position.needsUpdate = true;
392
+ normal.needsUpdate = true;
393
+ vehicleMesh.visible = true;
394
+ const shadow = state.shadows === false ? [] : partShadows(parts, v.y, state.sky.sun.azimuth, state.sky.sun.altitude);
395
+ const geometry = new T.BufferGeometry();
396
+ geometry.setAttribute("position", new T.BufferAttribute(new Float32Array(shadow), 3));
397
+ geometry.setAttribute("uv", new T.BufferAttribute(new Float32Array((shadow.length / 3) * 2).map((_, i) => (i % 2 === 1 ? 0 : 0.5)), 2));
398
+ if (vehicleShadow === undefined) {
399
+ vehicleShadow = new T.Mesh(geometry, shadowMaterial);
400
+ vehicleShadow.frustumCulled = false;
401
+ vehicleShadow.renderOrder = 2;
402
+ scene.add(vehicleShadow);
403
+ }
404
+ else {
405
+ vehicleShadow.geometry.dispose();
406
+ vehicleShadow.geometry = geometry;
407
+ }
408
+ vehicleShadow.visible = true;
409
+ };
410
+ // the driven path: a strip like the published traverse's, grown as the rover goes (room for 6,000 points)
411
+ const TRAIL_MAX = 6000;
412
+ let trailMesh;
413
+ let trailMaterialDriven;
414
+ let trailBuilt = 0;
415
+ const makeTrail = (state) => {
416
+ const points = state.trail;
417
+ if (points === undefined || points.length < 4) {
418
+ if (trailMesh !== undefined)
419
+ trailMesh.visible = false;
420
+ trailBuilt = 0;
421
+ return;
422
+ }
423
+ if (trailMesh === undefined) {
424
+ const geometry = new T.BufferGeometry();
425
+ geometry.setAttribute("position", new T.BufferAttribute(new Float32Array(TRAIL_MAX * 2 * 3), 3));
426
+ geometry.setAttribute("uv", new T.BufferAttribute(new Float32Array(TRAIL_MAX * 2 * 2), 2));
427
+ const indices = new Uint32Array((TRAIL_MAX - 1) * 6);
428
+ for (let i = 1; i < TRAIL_MAX; i += 1)
429
+ indices.set([2 * i - 2, 2 * i - 1, 2 * i, 2 * i - 1, 2 * i + 1, 2 * i], (i - 1) * 6);
430
+ geometry.setIndex(new T.BufferAttribute(indices, 1));
431
+ const material = new T.ShaderMaterial({ vertexShader: TRACK_VERTEX, fragmentShader: TRACK_FRAGMENT, uniforms, transparent: true, depthWrite: false, side: 2 });
432
+ material.polygonOffset = true;
433
+ material.polygonOffsetFactor = -3;
434
+ material.polygonOffsetUnits = -3;
435
+ trailMaterialDriven = material;
436
+ trailMesh = new T.Mesh(geometry, material);
437
+ trailMesh.frustumCulled = false;
438
+ trailMesh.renderOrder = 0.6;
439
+ scene.add(trailMesh);
440
+ }
441
+ const count = Math.min(TRAIL_MAX, points.length / 2);
442
+ if (count < trailBuilt)
443
+ trailBuilt = 0;
444
+ const position = trailMesh.geometry.getAttribute("position").array;
445
+ const uv = trailMesh.geometry.getAttribute("uv").array;
446
+ let along = trailBuilt > 0 ? uv[(trailBuilt - 1) * 4] : 0;
447
+ for (let i = Math.max(0, trailBuilt - 1); i < count; i += 1) {
448
+ const a = Math.max(0, i - 1);
449
+ const b = Math.min(count - 1, i + 1);
450
+ const [dx, dy] = [points[2 * b] - points[2 * a], points[2 * b + 1] - points[2 * a + 1]];
451
+ const len = Math.hypot(dx, dy) || 1;
452
+ const [nx, ny] = [-dy / len, dx / len];
453
+ if (i > 0)
454
+ along += Math.hypot(points[2 * i] - points[2 * i - 2], points[2 * i + 1] - points[2 * i - 1]);
455
+ for (const side of [-1, 1]) {
456
+ const k = i * 2 + (side === 1 ? 1 : 0);
457
+ position[k * 3] = points[2 * i] + nx * 1.4 * side;
458
+ position[k * 3 + 1] = points[2 * i + 1] + ny * 1.4 * side;
459
+ position[k * 3 + 2] = 0;
460
+ uv[k * 2] = along;
461
+ uv[k * 2 + 1] = side;
462
+ }
463
+ }
464
+ trailBuilt = count;
465
+ trailMesh.geometry.getAttribute("position").needsUpdate = true;
466
+ trailMesh.geometry.getAttribute("uv").needsUpdate = true;
467
+ trailMesh.geometry.setDrawRange(0, Math.max(0, (count - 1) * 6));
468
+ trailMesh.visible = true;
469
+ };
470
+ // the dust: one small square for each grain in the pool, in the corners of a fixed set of triangles
471
+ let dustMesh;
472
+ let dustMaterial;
473
+ const dustUniforms = { uVP: uniforms.uVP, uRight: { value: new T.Vector3(1, 0, 0) }, uUp: { value: new T.Vector3(0, 1, 0) }, uSize: { value: 0.022 } };
474
+ const makeDust = (state) => {
475
+ const grains = state.dust;
476
+ if (grains === undefined) {
477
+ if (dustMesh !== undefined)
478
+ dustMesh.visible = false;
479
+ return;
480
+ }
481
+ const n = grains.length / 3;
482
+ if (dustMesh === undefined) {
483
+ const geometry = new T.BufferGeometry();
484
+ geometry.setAttribute("position", new T.BufferAttribute(new Float32Array(n * 4 * 3), 3));
485
+ const uv = new Float32Array(n * 4 * 2);
486
+ const index = new Uint32Array(n * 6);
487
+ for (let i = 0; i < n; i += 1) {
488
+ uv.set([0, 0, 1, 0, 1, 1, 0, 1], i * 8);
489
+ index.set([i * 4, i * 4 + 1, i * 4 + 2, i * 4, i * 4 + 2, i * 4 + 3], i * 6);
490
+ }
491
+ geometry.setAttribute("uv", new T.BufferAttribute(uv, 2));
492
+ geometry.setIndex(new T.BufferAttribute(index, 1));
493
+ const material = new T.ShaderMaterial({ vertexShader: DUST_VERTEX, fragmentShader: DUST_FRAGMENT, uniforms: dustUniforms, transparent: true, depthWrite: false });
494
+ dustMaterial = material;
495
+ dustMesh = new T.Mesh(geometry, material);
496
+ dustMesh.frustumCulled = false;
497
+ dustMesh.renderOrder = 3;
498
+ scene.add(dustMesh);
499
+ }
500
+ const position = dustMesh.geometry.getAttribute("position");
501
+ const array = position.array;
502
+ for (let i = 0; i < n; i += 1)
503
+ for (let c = 0; c < 4; c += 1)
504
+ array.set([grains[i * 3], grains[i * 3 + 1], grains[i * 3 + 2]], (i * 4 + c) * 3);
505
+ position.needsUpdate = true;
506
+ const axes = cameraAxes(state.look);
507
+ dustUniforms.uRight.value.set(axes.right[0], axes.right[1], axes.right[2]);
508
+ dustUniforms.uUp.value.set(axes.up[0], axes.up[1], axes.up[2]);
509
+ dustMesh.visible = true;
510
+ };
336
511
  let measuring = false;
337
512
  let drawMs;
338
513
  let aspect = context.width / Math.max(1, context.height);
@@ -346,6 +521,9 @@ export function createSurfaceItem(options) {
346
521
  fullPixel = (2 * Math.tan((look.fov * Math.PI) / 360)) / pixelHeight;
347
522
  makeRocks(state);
348
523
  makeObjects(state);
524
+ makeVehicle(state);
525
+ makeTrail(state);
526
+ makeDust(state);
349
527
  measuring = state.measure === true;
350
528
  const world = new T.Vector3(eye.east, eye.up, -eye.north);
351
529
  const vp = viewProjection([world.x, world.y, world.z], look, aspect);
@@ -479,6 +657,12 @@ export function createSurfaceItem(options) {
479
657
  objectShadowMesh?.geometry.dispose();
480
658
  trackGeometry?.dispose();
481
659
  trackMaterial?.dispose();
660
+ vehicleMesh?.geometry.dispose();
661
+ vehicleShadow?.geometry.dispose();
662
+ trailMesh?.geometry.dispose();
663
+ dustMesh?.geometry.dispose();
664
+ trailMaterialDriven?.dispose();
665
+ dustMaterial?.dispose();
482
666
  objectMaterial.dispose();
483
667
  blitMaterial.dispose();
484
668
  },
@@ -47,8 +47,8 @@ export declare function placePart(part: Part, east: number, base: number, north:
47
47
  export declare function landerParts(): Part[];
48
48
  /**
49
49
  * The lunar rover in its own frame (x right, z forward, the middle of its wheelbase on the ground at the origin): a frame and floor, four wheels (parts 0 to 3: front left, front right, rear left, rear right) with a
50
- * fender over each, two seats, the console with its handle, the dish on its mast, the television camera on its own mast, a whip antenna and the boxes at both ends. Sizes from the published ones (3.1 m long, 2.3 m
51
- * wide, wheels 0.82 m across, the wheelbase 2.3 m).
50
+ * fender over each, two seats, the console with its handle, the dish on its mast, the television camera on its own mast, a whip antenna and the boxes at both ends. Sizes from the published ones (about 3.05 m long, 2.13 m
51
+ * wide, wheels 0.81 m across, the wheelbase 2.29 m).
52
52
  *
53
53
  * @returns The parts.
54
54
  *
@@ -171,8 +171,8 @@ export function landerParts() {
171
171
  }
172
172
  /**
173
173
  * The lunar rover in its own frame (x right, z forward, the middle of its wheelbase on the ground at the origin): a frame and floor, four wheels (parts 0 to 3: front left, front right, rear left, rear right) with a
174
- * fender over each, two seats, the console with its handle, the dish on its mast, the television camera on its own mast, a whip antenna and the boxes at both ends. Sizes from the published ones (3.1 m long, 2.3 m
175
- * wide, wheels 0.82 m across, the wheelbase 2.3 m).
174
+ * fender over each, two seats, the console with its handle, the dish on its mast, the television camera on its own mast, a whip antenna and the boxes at both ends. Sizes from the published ones (about 3.05 m long, 2.13 m
175
+ * wide, wheels 0.81 m across, the wheelbase 2.29 m).
176
176
  *
177
177
  * @returns The parts.
178
178
  *
@@ -198,7 +198,7 @@ export function roverParts() {
198
198
  parts.push(box([0, 0.57, -1.1], [1.15, 0.03, 0.6], 0, 1.0, 0, grey));
199
199
  const wheels = [[-1, 1], [1, 1], [-1, -1], [1, -1]];
200
200
  wheels.forEach(([sx, sz], index) => {
201
- const centre = [sx * 1.03, 0.41, sz * 1.15];
201
+ const centre = [sx * 0.95, 0.41, sz * 1.15];
202
202
  // a wheel of wire mesh (dark, with a lighter hub), its strut to the frame and its fender over the top
203
203
  const wheel = cylinder([-0.115, 0, 0], 0.41, 0.23, 16, 0.55, true, DARK);
204
204
  const hub = cylinder([-0.12, 0, 0], 0.16, 0.24, 10, 1.0, true, [0.7, 0.72, 0.76]);
@@ -211,7 +211,7 @@ export function roverParts() {
211
211
  }
212
212
  parts.push(part);
213
213
  }
214
- parts.push(strut([sx * 0.55, 0.55, sz * 1.15], [sx * 0.95, 0.45, sz * 1.15], 0.07, 1.1, grey));
214
+ parts.push(strut([sx * 0.55, 0.55, sz * 1.15], [sx * 0.85, 0.45, sz * 1.15], 0.07, 1.1, grey));
215
215
  // the fender: five narrow boards along an arc a hand above the tyre
216
216
  for (let s = 0; s < 5; s += 1) {
217
217
  const a0 = ((-65 + s * 26) * Math.PI) / 180;
@@ -234,11 +234,11 @@ export function roverParts() {
234
234
  parts.push(strut([0, 1.1, 0.35], [0, 1.4, 0.3], 0.03, 1.0, DARK));
235
235
  parts.push(box([0, 1.42, 0.3], [0.2, 0.04, 0.05], 0, 1.0, 0, DARK));
236
236
  // the dish on its mast at the front, turned up and back toward the Earth, and the camera's own mast beside it
237
- parts.push(strut([0, 0.6, 1.2], [0, 1.65, 1.2], 0.05, 1.2, grey));
238
- parts.push(dish([0, 1.75, 1.2], [0, 0.55, -0.55], 0.46, 0.14, 14, 1.4, [0.95, 0.95, 0.97]));
239
- parts.push(strut([-0.38, 0.6, 1.3], [-0.38, 1.4, 1.3], 0.04, 1.2, grey));
240
- parts.push(box([-0.38, 1.5, 1.3], [0.26, 0.16, 0.18], 0, 1.0, 0, [0.5, 0.52, 0.56]));
241
- parts.push(strut([0.4, 0.6, 1.05], [0.4, 1.8, 1.05], 0.012, 1.0, DARK));
237
+ parts.push(strut([0, 0.6, 1.2], [0, 2.1, 1.2], 0.05, 1.2, grey));
238
+ parts.push(dish([0, 2.2, 1.2], [0, 0.55, -0.55], 0.46, 0.14, 14, 1.4, [0.95, 0.95, 0.97]));
239
+ parts.push(strut([0.5, 0.6, 1.3], [0.5, 1.3, 1.3], 0.04, 1.2, grey));
240
+ parts.push(box([0.5, 1.4, 1.3], [0.26, 0.16, 0.18], 0, 1.0, 0, [0.5, 0.52, 0.56]));
241
+ parts.push(strut([-0.8, 0.6, 1.3], [-0.8, 1.9, 1.3], 0.012, 1.0, DARK));
242
242
  // the boxes: the batteries at the front, the tools at the back
243
243
  for (const x of [-0.4, 0.4])
244
244
  parts.push(box([x, 0.76, 0.85], [0.36, 0.26, 0.38], 0, 1.0, 0, SILVER));
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.47.0";
1
+ export declare const VERSION = "0.49.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.47.0";
1
+ export const VERSION = "0.49.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.47.0",
3
+ "version": "0.49.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",