@woosh/meep-engine 2.118.2 → 2.118.4

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.
Files changed (56) hide show
  1. package/build/meep.cjs +116 -110
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +116 -110
  4. package/package.json +5 -5
  5. package/src/core/binary/EndianType.d.ts +3 -0
  6. package/src/core/binary/EndianType.d.ts.map +1 -1
  7. package/src/core/binary/EndianType.js +2 -1
  8. package/src/core/binary/uint8_to_float.d.ts.map +1 -1
  9. package/src/core/binary/uint8_to_float.js +5 -0
  10. package/src/core/collection/queue/Deque.d.ts.map +1 -1
  11. package/src/core/collection/queue/Deque.js +32 -32
  12. package/src/core/collection/table/RowFirstTable.d.ts.map +1 -1
  13. package/src/core/collection/table/RowFirstTable.js +2 -0
  14. package/src/core/color/Color.js +3 -3
  15. package/src/core/color/kelvin/rgb_to_kelvin.d.ts.map +1 -1
  16. package/src/core/color/kelvin/rgb_to_kelvin.js +16 -7
  17. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_attached_to_vertex.d.ts.map +1 -0
  18. package/src/core/geom/Vector3.d.ts.map +1 -1
  19. package/src/core/geom/Vector3.js +5 -19
  20. package/src/core/geom/packing/computeBoundingSphereOfSpheres.js +1 -1
  21. package/src/core/math/compute_legendre_polynomial.d.ts +1 -1
  22. package/src/core/math/compute_legendre_polynomial.d.ts.map +1 -1
  23. package/src/core/math/compute_legendre_polynomial.js +6 -1
  24. package/src/core/math/max3.d.ts.map +1 -1
  25. package/src/core/math/max3.js +4 -0
  26. package/src/core/math/solveQuadratic.d.ts.map +1 -1
  27. package/src/core/math/solveQuadratic.js +5 -1
  28. package/src/core/primitives/boolean/compareBooleans.js +2 -0
  29. package/src/core/primitives/boolean/computeBooleanHash.d.ts +7 -0
  30. package/src/core/primitives/boolean/computeBooleanHash.d.ts.map +1 -0
  31. package/src/core/primitives/boolean/computeBooleanHash.js +8 -0
  32. package/src/core/primitives/numbers/computeHashFloat.d.ts.map +1 -1
  33. package/src/core/primitives/numbers/computeHashFloat.js +4 -2
  34. package/src/engine/animation/async/TimeSeries.d.ts +5 -1
  35. package/src/engine/animation/async/TimeSeries.d.ts.map +1 -1
  36. package/src/engine/animation/async/TimeSeries.js +14 -2
  37. package/src/engine/asset/loaders/material/computeTextureHash.d.ts.map +1 -1
  38. package/src/engine/asset/loaders/material/computeTextureHash.js +5 -0
  39. package/src/engine/ecs/gui/position/ViewportPosition.d.ts +0 -5
  40. package/src/engine/ecs/gui/position/ViewportPosition.d.ts.map +1 -1
  41. package/src/engine/ecs/gui/position/ViewportPosition.js +42 -53
  42. package/src/engine/ecs/speaker/VoiceSystem.d.ts +2 -3
  43. package/src/engine/ecs/speaker/VoiceSystem.d.ts.map +1 -1
  44. package/src/engine/graphics/canvas/computeHtmlCanvasElementHash.d.ts +7 -0
  45. package/src/engine/graphics/canvas/computeHtmlCanvasElementHash.d.ts.map +1 -0
  46. package/src/engine/graphics/canvas/computeHtmlCanvasElementHash.js +12 -0
  47. package/src/engine/graphics/canvas/computeImageCanvasEquality.js +3 -1
  48. package/src/engine/graphics/sh3/lpv/find_max_depth_radius_for_point.js +2 -2
  49. package/src/engine/graphics/texture/html_canvas_to_rendering_context2d_cached.d.ts +7 -0
  50. package/src/engine/graphics/texture/html_canvas_to_rendering_context2d_cached.d.ts.map +1 -0
  51. package/src/engine/graphics/texture/html_canvas_to_rendering_context2d_cached.js +20 -0
  52. package/src/engine/graphics/texture/html_canvas_to_sampler2d.d.ts.map +1 -1
  53. package/src/engine/graphics/texture/html_canvas_to_sampler2d.js +2 -11
  54. package/src/core/geometry/3d/tetrahedra/tetrahedral_mesh_find_tets_attached_to_vertex.d.ts.map +0 -1
  55. /package/src/core/{geometry → geom}/3d/tetrahedra/tetrahedral_mesh_find_tets_attached_to_vertex.d.ts +0 -0
  56. /package/src/core/{geometry → geom}/3d/tetrahedra/tetrahedral_mesh_find_tets_attached_to_vertex.js +0 -0
package/build/meep.cjs CHANGED
@@ -1767,6 +1767,12 @@ function lerp$1(a, b, fraction) {
1767
1767
  return (b - a) * fraction + a;
1768
1768
  }
1769
1769
 
1770
+ /**
1771
+ * equal to `Math.pow(2,32) - 1`
1772
+ * @type {number}
1773
+ */
1774
+ const UINT32_MAX = 4294967295;
1775
+
1770
1776
  /**
1771
1777
  *
1772
1778
  * @param {number} v
@@ -1774,12 +1780,12 @@ function lerp$1(a, b, fraction) {
1774
1780
  */
1775
1781
  function computeHashFloat(v) {
1776
1782
  //we break the number up into fractional and whole parts
1777
- const whole = v | 0;
1783
+ const whole = v >> 0;
1778
1784
 
1779
1785
  const fraction = v - whole;
1780
1786
 
1781
1787
  //fractional part is scaled up into int32 range, this inexact method, as it will produce 0 hash for values below a certain threshold
1782
- const fractionHash = fraction * 1367130550;
1788
+ const fractionHash = fraction * UINT32_MAX;
1783
1789
 
1784
1790
  //take XOR of both parts
1785
1791
  return fractionHash ^ whole;
@@ -2124,10 +2130,8 @@ function v3_slerp(
2124
2130
 
2125
2131
  /**
2126
2132
  * @author Alex Goldring
2127
- * @copyright Alex Goldring 2015
2133
+ * @copyright Alex Goldring 2015-2024
2128
2134
  */
2129
-
2130
-
2131
2135
  let Vector3$1 = class Vector3 {
2132
2136
  /**
2133
2137
  *
@@ -3017,7 +3021,7 @@ let Vector3$1 = class Vector3 {
3017
3021
  * @deprecated use dedicated method directly instead
3018
3022
  */
3019
3023
  fromBinaryBufferFloat32_EqualityEncoded(buffer) {
3020
- throw new Error('deprecated, use v3_binary_equality_decode')
3024
+ throw new Error('deprecated, use v3_binary_equality_decode')
3021
3025
  }
3022
3026
 
3023
3027
  hash() {
@@ -3178,19 +3182,7 @@ Vector3$1.prototype.isVector3 = true;
3178
3182
  * @readonly
3179
3183
  * @type {string}
3180
3184
  */
3181
- Vector3$1.typeName = "Vector3";
3182
-
3183
- /**
3184
- * @deprecated use {@link v3_dot} directly instead
3185
- * @param {number} x0
3186
- * @param {number} y0
3187
- * @param {number} z0
3188
- * @param {number} x1
3189
- * @param {number} y1
3190
- * @param {number} z1
3191
- * @returns {number}
3192
- */
3193
- Vector3$1._dot = v3_dot;
3185
+ Vector3$1.typeName = "Vector3";
3194
3186
 
3195
3187
  const scratch_v3_a = new Vector3$1();
3196
3188
  const scratch_v3_b = new Vector3$1();
@@ -50301,6 +50293,7 @@ function float_to_uint8(v) {
50301
50293
  * @returns {number}
50302
50294
  */
50303
50295
  function uint8_to_float(v) {
50296
+
50304
50297
  return v / 255;
50305
50298
  }
50306
50299
 
@@ -51203,18 +51196,28 @@ const context_cache = new WeakMap();
51203
51196
  /**
51204
51197
  *
51205
51198
  * @param {HTMLCanvasElement} canvas
51206
- * @returns {Sampler2D}
51199
+ * @returns {CanvasRenderingContext2D}
51207
51200
  */
51208
- function html_canvas_to_sampler2d(canvas) {
51209
- const width = canvas.width;
51210
- const height = canvas.height;
51211
-
51201
+ function html_canvas_to_rendering_context2d_cached(canvas) {
51212
51202
  let context = context_cache.get(canvas);
51213
51203
 
51214
51204
  if (context === undefined) {
51215
51205
  context = canvas.getContext("2d");
51216
51206
  context_cache.set(canvas, context);
51217
51207
  }
51208
+ return context;
51209
+ }
51210
+
51211
+ /**
51212
+ *
51213
+ * @param {HTMLCanvasElement} canvas
51214
+ * @returns {Sampler2D}
51215
+ */
51216
+ function html_canvas_to_sampler2d(canvas) {
51217
+ const width = canvas.width;
51218
+ const height = canvas.height;
51219
+
51220
+ const context = html_canvas_to_rendering_context2d_cached(canvas);
51218
51221
 
51219
51222
  const imageData = context.getImageData(0, 0, width, height);
51220
51223
 
@@ -52059,12 +52062,6 @@ class TerrainPreview {
52059
52062
  }
52060
52063
  }
52061
52064
 
52062
- /**
52063
- * equal to `Math.pow(2,32) - 1`
52064
- * @type {number}
52065
- */
52066
- const UINT32_MAX = 4294967295;
52067
-
52068
52065
  /**
52069
52066
  * This is essentially a {@link memcopy} implementation for ArrayBuffers
52070
52067
  * NOTE: allocates light-weight typed arrays under the hood, so beware of potential GC implications. Generally not an issue, unless you're copying very large number of very small arrays, consider alternatives such as {@link array_copy} instead
@@ -53921,9 +53918,9 @@ class Color {
53921
53918
 
53922
53919
  /**
53923
53920
  *
53924
- * @param {number} r
53925
- * @param {number} g
53926
- * @param {number} b
53921
+ * @param {number} r [0..255]
53922
+ * @param {number} g [0..255]
53923
+ * @param {number} b [0..255]
53927
53924
  */
53928
53925
  setRGBUint8(r, g, b) {
53929
53926
  this.setRGB(
@@ -55310,13 +55307,17 @@ function v3_morton_encode_bounded(x, y, z, bounds) {
55310
55307
  function max3(a, b, c) {
55311
55308
 
55312
55309
  let v = a;
55310
+
55313
55311
  if (v < b) {
55314
55312
  v = b;
55315
55313
  }
55314
+
55316
55315
  if (v < c) {
55317
55316
  v = c;
55318
55317
  }
55318
+
55319
55319
  return v;
55320
+
55320
55321
  }
55321
55322
 
55322
55323
  /**
@@ -76451,6 +76452,17 @@ function murmur3_32(key, seed) {
76451
76452
  return h1 >>> 0;
76452
76453
  }
76453
76454
 
76455
+ /**
76456
+ *
76457
+ * @param {HTMLCanvasElement} canvas
76458
+ * @returns {number}
76459
+ */
76460
+ function computeHtmlCanvasElementHash(canvas) {
76461
+ const sampler = html_canvas_to_sampler2d(canvas);
76462
+
76463
+ return sampler.hash();
76464
+ }
76465
+
76454
76466
  /**
76455
76467
  * Guards against cases where ImageBitmap doesn't exist
76456
76468
  * @param {*} image
@@ -76695,6 +76707,10 @@ function computeImageDataHash(image) {
76695
76707
 
76696
76708
  result = computeStringHash(image.src);
76697
76709
 
76710
+ }else if(image instanceof HTMLCanvasElement) {
76711
+
76712
+ result = computeHtmlCanvasElementHash(image);
76713
+
76698
76714
  }
76699
76715
 
76700
76716
  let width = 0;
@@ -85293,6 +85309,13 @@ const STATUS_FULL = 0;
85293
85309
  const STATUS_EMPTY = 1;
85294
85310
  const STATUS_NORMAL = 2;
85295
85311
 
85312
+ /**
85313
+ * When growing underlying array, how much to grow by. This is a multiplier.
85314
+ * Must be greater than 1
85315
+ * @type {number}
85316
+ */
85317
+ const GROWTH_FACTOR = 2;
85318
+
85296
85319
  const EMPTY_ARRAY = new Array(0);
85297
85320
 
85298
85321
  /**
@@ -85309,14 +85332,16 @@ class Deque {
85309
85332
  * @private
85310
85333
  */
85311
85334
  #data = EMPTY_ARRAY;
85335
+
85312
85336
  /**
85313
- *
85337
+ * Index of the front of the queue inside the internal data array
85314
85338
  * @type {number}
85315
85339
  * @private
85316
85340
  */
85317
85341
  #head = 0;
85342
+
85318
85343
  /**
85319
- *
85344
+ * Index of the back of the queue inside the internal data array
85320
85345
  * @type {number}
85321
85346
  * @private
85322
85347
  */
@@ -85398,7 +85423,7 @@ class Deque {
85398
85423
  }
85399
85424
 
85400
85425
  // double existing length
85401
- let new_length = length * 2;
85426
+ let new_length = length * GROWTH_FACTOR;
85402
85427
 
85403
85428
  if (new_length > UINT32_MAX) {
85404
85429
  // clamp to max uint32 value
@@ -85471,41 +85496,23 @@ class Deque {
85471
85496
  /**
85472
85497
  *
85473
85498
  * @param {number} current
85474
- * @param {boolean} shift_front should we shift elements before the removed element or after?
85475
85499
  * @private
85476
85500
  */
85477
- #remove_internal(current, shift_front) {
85501
+ #remove_internal_shift_backward(current) {
85478
85502
  let cursor = current;
85479
85503
 
85480
- if (shift_front) {
85481
-
85482
- // shift towards tail
85483
-
85484
- const head = this.#head;
85504
+ // shift towards head, this has a better data access pattern than shifting the other way as we're going through the data in forward sequence
85485
85505
 
85486
- while (cursor !== head) {
85487
- const next = this.#circular_previous_position(cursor);
85488
- this.#data[cursor] = this.#data[next];
85489
- cursor = next;
85490
- }
85491
-
85492
- this.#head = this.#circular_next_position(head);
85493
-
85494
- } else {
85495
-
85496
- // shift towards head
85497
-
85498
- const tail = this.#tail;
85506
+ const tail = this.#tail;
85499
85507
 
85500
- while (cursor !== tail) {
85501
- const next = this.#circular_next_position(cursor);
85502
- this.#data[cursor] = this.#data[next];
85503
- cursor = next;
85504
- }
85508
+ while (cursor !== tail) {
85509
+ const next = this.#circular_next_position(cursor);
85510
+ this.#data[cursor] = this.#data[next];
85511
+ cursor = next;
85512
+ }
85505
85513
 
85506
- this.#tail = this.#circular_previous_position(tail);
85514
+ this.#tail = this.#circular_previous_position(tail);
85507
85515
 
85508
- }
85509
85516
 
85510
85517
  // fill in slot of last moved element
85511
85518
  this.#data[cursor] = undefined;
@@ -85525,7 +85532,7 @@ class Deque {
85525
85532
  return false;
85526
85533
  }
85527
85534
 
85528
- this.#remove_internal(i, true);
85535
+ this.#remove_internal_shift_backward(i);
85529
85536
 
85530
85537
  return true;
85531
85538
  }
@@ -85687,12 +85694,21 @@ class Deque {
85687
85694
  Stack methods
85688
85695
  */
85689
85696
 
85697
+ /**
85698
+ * Stack operation. Alias of {@link Deque.prototype.getFirst}
85699
+ */
85690
85700
  Deque.prototype.peek = Deque.prototype.getFirst;
85701
+ /**
85702
+ * Stack operation. Alias of {@link Deque.prototype.addFirst}
85703
+ */
85691
85704
  Deque.prototype.push = Deque.prototype.addFirst;
85705
+ /**
85706
+ * Stack operation. Alias of {@link Deque.prototype.removeFirst}
85707
+ */
85692
85708
  Deque.prototype.pop = Deque.prototype.removeFirst;
85693
85709
 
85694
85710
  /**
85695
- * Standard queue method
85711
+ * Alias of {@link Deque.prototype.addLast}
85696
85712
  */
85697
85713
  Deque.prototype.add = Deque.prototype.addLast;
85698
85714
 
@@ -103212,59 +103228,49 @@ GUIElement.serializable = true;
103212
103228
 
103213
103229
  class ViewportPosition {
103214
103230
  /**
103215
- *
103216
- * @constructor
103231
+ * Clip-scale position, on-screen values are in range of 0 to 1
103232
+ * @type {Vector2}
103217
103233
  */
103218
- constructor(options) {
103219
- /**
103220
- * Clip-scale position, on-screen values are in range of 0 to 1
103221
- * @type {Vector2}
103222
- */
103223
- this.position = new Vector2();
103224
-
103225
- /**
103226
- * Fixed offset in pixels
103227
- * @type {Vector2}
103228
- */
103229
- this.offset = new Vector2();
103230
- /**
103231
- * ranges from 0..1 in both X and Y, controls anchor point of element positioning
103232
- * @type {Vector2}
103233
- */
103234
- this.anchor = new Vector2(0, 0);
103234
+ position = new Vector2();
103235
103235
 
103236
+ /**
103237
+ * Fixed offset in pixels
103238
+ * @type {Vector2}
103239
+ */
103240
+ offset = new Vector2();
103241
+ /**
103242
+ * ranges from 0..1 in both X and Y, controls anchor point of element positioning
103243
+ * @type {Vector2}
103244
+ */
103245
+ anchor = new Vector2(0, 0);
103236
103246
 
103237
- /**
103238
- * Makes display element avoid overlap with GUI elements
103239
- * @see GUIElement
103240
- * @type {boolean}
103241
- */
103242
- this.resolveGuiCollisions = false;
103243
103247
 
103244
- /**
103245
- * How far should the HUD stay away from the edge if it's sticky
103246
- * @see stickToScreenEdge
103247
- * @type {number}
103248
- */
103249
- this.screenEdgeWidth = 10;
103248
+ /**
103249
+ * Makes display element avoid overlap with GUI elements
103250
+ * @see GUIElement
103251
+ * @type {boolean}
103252
+ */
103253
+ resolveGuiCollisions = false;
103250
103254
 
103255
+ /**
103256
+ * How far should the HUD stay away from the edge if it's sticky
103257
+ * @see stickToScreenEdge
103258
+ * @type {number}
103259
+ */
103260
+ screenEdgeWidth = 10;
103251
103261
 
103252
- /**
103253
- * Controls whenever or not HUD should remain on the screen when it gets to the edge
103254
- * @type {boolean}
103255
- */
103256
- this.stickToScreenEdge = false;
103257
103262
 
103258
- /**
103259
- * Can be used to enable and disable positioning
103260
- * @type {ObservedBoolean}
103261
- */
103262
- this.enabled = new ObservedBoolean(true);
103263
+ /**
103264
+ * Controls whenever or not HUD should remain on the screen when it gets to the edge
103265
+ * @type {boolean}
103266
+ */
103267
+ stickToScreenEdge = false;
103263
103268
 
103264
- if (options !== undefined) {
103265
- this.fromJSON(options);
103266
- }
103267
- }
103269
+ /**
103270
+ * Can be used to enable and disable positioning
103271
+ * @type {ObservedBoolean}
103272
+ */
103273
+ enabled = new ObservedBoolean(true);
103268
103274
 
103269
103275
  /**
103270
103276
  *