@woosh/meep-engine 2.109.24 → 2.109.25

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 (47) hide show
  1. package/build/meep.cjs +231 -104
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +231 -104
  4. package/package.json +1 -1
  5. package/src/core/collection/heap/FastBinaryHeap.d.ts +17 -10
  6. package/src/core/collection/heap/FastBinaryHeap.d.ts.map +1 -1
  7. package/src/core/collection/heap/FastBinaryHeap.js +33 -23
  8. package/src/core/collection/heap/FastBinaryHeap.spec.js +10 -10
  9. package/src/core/collection/table/RowFirstTable.d.ts +10 -7
  10. package/src/core/collection/table/RowFirstTable.d.ts.map +1 -1
  11. package/src/core/collection/table/RowFirstTable.js +23 -6
  12. package/src/core/geom/3d/normal/octahedron/encode_unit_to_octahedron.js +2 -2
  13. package/src/core/geom/packing/max-rect/MaxRectanglesPacker.js +2 -2
  14. package/src/engine/animation/async/TimeSeries.d.ts.map +1 -1
  15. package/src/engine/animation/async/TimeSeries.js +6 -2
  16. package/src/engine/animation/async/table_find_min_index_in_ordered_column.d.ts +9 -0
  17. package/src/engine/animation/async/table_find_min_index_in_ordered_column.d.ts.map +1 -0
  18. package/src/engine/animation/async/{findSampleIndex.js → table_find_min_index_in_ordered_column.js} +5 -4
  19. package/src/engine/asset/AssetManager.js +1 -1
  20. package/src/engine/graphics/sh3/gi/material/common.glsl +1 -1
  21. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +1 -1
  22. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.d.ts.map +1 -1
  23. package/src/engine/graphics/sh3/lpv/depth/octahedral/bake_octahedral_depth_map.js +5 -0
  24. package/src/engine/graphics/sh3/prototypeSH3Probe.js +2 -2
  25. package/src/engine/input/devices/InputDeviceSwitch.d.ts.map +1 -1
  26. package/src/engine/input/devices/InputDeviceSwitch.js +18 -0
  27. package/src/engine/input/devices/KeyboardDevice.d.ts.map +1 -1
  28. package/src/engine/input/devices/KeyboardDevice.js +4 -41
  29. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts +11 -0
  30. package/src/engine/input/devices/LocationalInteractionMetadata.d.ts.map +1 -0
  31. package/src/engine/input/devices/LocationalInteractionMetadata.js +18 -0
  32. package/src/engine/input/devices/PointerDevice.d.ts.map +1 -1
  33. package/src/engine/input/devices/PointerDevice.js +90 -37
  34. package/src/engine/input/devices/eventToSourceIdentifier.d.ts +7 -0
  35. package/src/engine/input/devices/eventToSourceIdentifier.d.ts.map +1 -0
  36. package/src/engine/input/devices/eventToSourceIdentifier.js +36 -0
  37. package/src/engine/input/devices/isHTMLElementFocusable.d.ts +6 -0
  38. package/src/engine/input/devices/isHTMLElementFocusable.d.ts.map +1 -0
  39. package/src/engine/input/devices/isHTMLElementFocusable.js +34 -0
  40. package/src/generation/grid/generation/discrete/GridTaskConnectRooms.js +3 -3
  41. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.d.ts.map +1 -1
  42. package/src/generation/grid/generation/discrete/layer/GridTaskBuildSourceDistanceMap.js +5 -5
  43. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.d.ts.map +1 -1
  44. package/src/generation/grid/generation/discrete/layer/GridTaskDistanceToMarkers.js +3 -3
  45. package/src/generation/grid/generation/road/GridTaskGenerateRoads.js +2 -2
  46. package/src/engine/animation/async/findSampleIndex.d.ts +0 -9
  47. package/src/engine/animation/async/findSampleIndex.d.ts.map +0 -1
package/build/meep.cjs CHANGED
@@ -84590,10 +84590,23 @@ class ViewStack extends View {
84590
84590
  }
84591
84591
 
84592
84592
  /**
84593
- * Min-Heap implementation with a score function. The data structure is a binary heap where elements are removed in order defined by scoring function
84593
+ * Min-Heap implementation with a score function.
84594
+ * The data structure is a binary heap where elements are removed in order defined by scoring function
84594
84595
  * @template T
84595
84596
  */
84596
- class BinaryHeap {
84597
+ class FastBinaryHeap {
84598
+ /**
84599
+ * @private
84600
+ * @type {T[]}
84601
+ */
84602
+ data = [];
84603
+
84604
+ /**
84605
+ * @private
84606
+ * @type {number}
84607
+ */
84608
+ length = 0;
84609
+
84597
84610
  /**
84598
84611
  * @template T
84599
84612
  * @param {function(el:T):number} scoreFunction
@@ -84607,17 +84620,6 @@ class BinaryHeap {
84607
84620
  */
84608
84621
  this.scoreFunction = scoreFunction;
84609
84622
 
84610
- /**
84611
- *
84612
- * @type {T[]}
84613
- */
84614
- this.data = [];
84615
-
84616
- /**
84617
- * @private
84618
- * @type {number}
84619
- */
84620
- this.length = 0;
84621
84623
  }
84622
84624
 
84623
84625
  /**
@@ -84687,19 +84689,19 @@ class BinaryHeap {
84687
84689
  if (right >= length) {
84688
84690
  //right node doesn't exist
84689
84691
 
84690
-
84691
84692
  if (scoreLeft >= scoreMin) {
84692
84693
  break;
84693
84694
  } else {
84694
84695
  minIndex = left;
84695
84696
  dataMin = dataLeft;
84696
84697
  }
84698
+
84697
84699
  } else {
84700
+
84698
84701
  //both left and right nodes exist
84699
84702
  const dataRight = data[right];
84700
84703
  const scoreRight = this.scoreFunction(dataRight);
84701
84704
 
84702
- //
84703
84705
  if (scoreLeft <= scoreRight) {
84704
84706
  if (scoreLeft >= scoreMin) {
84705
84707
  break;
@@ -84715,6 +84717,7 @@ class BinaryHeap {
84715
84717
  dataMin = dataRight;
84716
84718
  }
84717
84719
  }
84720
+
84718
84721
  }
84719
84722
 
84720
84723
  //swap positions
@@ -84732,7 +84735,6 @@ class BinaryHeap {
84732
84735
  */
84733
84736
  pop() {
84734
84737
 
84735
-
84736
84738
  this.length--;
84737
84739
 
84738
84740
  const new_length = this.length;
@@ -84741,19 +84743,20 @@ class BinaryHeap {
84741
84743
 
84742
84744
  if (new_length === 0) {
84743
84745
 
84746
+ // this was the last element in the heap
84747
+
84744
84748
  return last;
84745
84749
 
84746
- } else {
84750
+ }
84747
84751
 
84748
- const ret = this.data[0];
84752
+ const ret = this.data[0];
84749
84753
 
84750
- this.data[0] = last;
84754
+ this.data[0] = last;
84751
84755
 
84752
- this.bubbleDown(0);
84756
+ this.bubbleDown(0);
84753
84757
 
84754
- return ret;
84758
+ return ret;
84755
84759
 
84756
- }
84757
84760
  }
84758
84761
 
84759
84762
  /**
@@ -84855,7 +84858,14 @@ class BinaryHeap {
84855
84858
 
84856
84859
  this.bubbleUp(position);
84857
84860
  }
84858
- }
84861
+ }
84862
+
84863
+ /**
84864
+ * Useful for type checks
84865
+ * @readonly
84866
+ * @type {boolean}
84867
+ */
84868
+ FastBinaryHeap.prototype.isFastBinaryHeap = true;
84859
84869
 
84860
84870
  /**
84861
84871
  * Decorator that wraps another map and lets you observe mutations
@@ -86045,7 +86055,7 @@ let Response$1 = class Response {
86045
86055
  };
86046
86056
 
86047
86057
  /**
86048
- * Used by the priority queue, so the priority is inverted as the BinaryHeap returns elements in ascending score order (from lowest)
86058
+ * Used by the priority queue, so the priority is inverted as the FastBinaryHeap returns elements in ascending score order (from lowest)
86049
86059
  * @param {PendingAsset} pending_asset
86050
86060
  * @returns {number}
86051
86061
  */
@@ -86080,7 +86090,7 @@ class AssetManager {
86080
86090
  * @type {BinaryHeap<PendingAsset>}
86081
86091
  * @private
86082
86092
  */
86083
- #pending_asset_wait_queue = new BinaryHeap(get_pending_asset_priority_score);
86093
+ #pending_asset_wait_queue = new FastBinaryHeap(get_pending_asset_priority_score);
86084
86094
  /**
86085
86095
  * Assets currently being processed by #loaders
86086
86096
  * @type {Set<PendingAsset>}
@@ -91139,6 +91149,59 @@ class InputDeviceSwitch {
91139
91149
  * @type {boolean}
91140
91150
  */
91141
91151
  is_down = false
91152
+
91153
+ press() {
91154
+ if (this.is_down) {
91155
+ return;
91156
+ }
91157
+
91158
+ this.is_down = true;
91159
+ this.down.send0();
91160
+ }
91161
+
91162
+ release() {
91163
+ if (!this.is_down) {
91164
+ return;
91165
+ }
91166
+
91167
+ this.is_down = false;
91168
+ this.up.send0();
91169
+ }
91170
+ }
91171
+
91172
+ /**
91173
+ *
91174
+ * @param thing
91175
+ * @param klass
91176
+ * @returns {boolean}
91177
+ */
91178
+ function isInstanceOf$1(thing, klass) {
91179
+ if (klass === undefined) {
91180
+ return false;
91181
+ }
91182
+ if (klass === null) {
91183
+ return false;
91184
+ }
91185
+
91186
+ if (typeof klass !== "object") {
91187
+ return false;
91188
+ }
91189
+
91190
+
91191
+ return thing instanceof klass;
91192
+ }
91193
+
91194
+ /**
91195
+ * Based on the article about focusable events: https://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
91196
+ * @param {Element} el
91197
+ */
91198
+ function isHTMLElementFocusable(el) {
91199
+ return isInstanceOf$1(el, HTMLInputElement)
91200
+ || isInstanceOf$1(el, HTMLSelectElement)
91201
+ || isInstanceOf$1(el, HTMLTextAreaElement)
91202
+ || isInstanceOf$1(el, HTMLAnchorElement)
91203
+ || isInstanceOf$1(el, HTMLButtonElement)
91204
+ || isInstanceOf$1(el, HTMLAreaElement)
91142
91205
  }
91143
91206
 
91144
91207
  /**
@@ -91248,41 +91311,6 @@ const KeyCodes = {
91248
91311
  'back_quote': 223
91249
91312
  };
91250
91313
 
91251
- /**
91252
- *
91253
- * @param thing
91254
- * @param klass
91255
- * @returns {boolean}
91256
- */
91257
- function isInstanceOf$1(thing, klass) {
91258
- if (klass === undefined) {
91259
- return false;
91260
- }
91261
- if (klass === null) {
91262
- return false;
91263
- }
91264
-
91265
- if (typeof klass !== "object") {
91266
- return false;
91267
- }
91268
-
91269
-
91270
- return thing instanceof klass;
91271
- }
91272
-
91273
- /**
91274
- * Based on the article about focusable events: https://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
91275
- * @param {Element} el
91276
- */
91277
- function isFocusable(el) {
91278
- return isInstanceOf$1(el, HTMLInputElement)
91279
- || isInstanceOf$1(el, HTMLSelectElement)
91280
- || isInstanceOf$1(el, HTMLTextAreaElement)
91281
- || isInstanceOf$1(el, HTMLAnchorElement)
91282
- || isInstanceOf$1(el, HTMLButtonElement)
91283
- || isInstanceOf$1(el, HTMLAreaElement)
91284
- }
91285
-
91286
91314
  /**
91287
91315
  * @readonly
91288
91316
  * @type {string[]}
@@ -91315,7 +91343,7 @@ class KeyboardDevice {
91315
91343
  Only element in focus receives keyboard events, so the element supplied here must be focusable in order to be able to receive events
91316
91344
  */
91317
91345
  if (
91318
- !isFocusable(domElement)
91346
+ !isHTMLElementFocusable(domElement)
91319
91347
  && domElement.getAttribute('tabindex') === null
91320
91348
  ) ;
91321
91349
 
@@ -91359,9 +91387,7 @@ class KeyboardDevice {
91359
91387
  if (keyName !== undefined) {
91360
91388
  const button = this.keys[keyName];
91361
91389
 
91362
- button.is_down = true;
91363
- button.down.send1(event);
91364
-
91390
+ button.press();
91365
91391
  }
91366
91392
  }
91367
91393
 
@@ -91381,8 +91407,7 @@ class KeyboardDevice {
91381
91407
  if (keyName !== undefined) {
91382
91408
  const button = this.keys[keyName];
91383
91409
 
91384
- button.is_down = false;
91385
- button.up.send1(event);
91410
+ button.release();
91386
91411
  }
91387
91412
  }
91388
91413
 
@@ -91429,6 +91454,60 @@ const TouchEvents = {
91429
91454
  Cancel: "touchcancel",
91430
91455
  };
91431
91456
 
91457
+ /**
91458
+ *
91459
+ * @param {TouchEvent|MouseEvent} event
91460
+ * @returns {number}
91461
+ */
91462
+ function eventToSourceIdentifier(event) {
91463
+ let device_id = 0;
91464
+ let source_id = 0;
91465
+
91466
+ if (event instanceof MouseEvent) {
91467
+
91468
+ // mouse
91469
+
91470
+ device_id = 1;
91471
+ source_id = event.button;
91472
+
91473
+ } else if (event instanceof TouchEvent) {
91474
+
91475
+ // touch
91476
+
91477
+ device_id = 2;
91478
+ const touches = event.changedTouches;
91479
+ const num_changes = touches.length;
91480
+
91481
+ if (num_changes > 0) {
91482
+ const touch = touches.item(0);
91483
+
91484
+ source_id = touch.identifier;
91485
+ }
91486
+
91487
+ }
91488
+
91489
+ return ((device_id & 0b11) << 29)
91490
+ | (source_id & 0b11111111111111111111111111111)
91491
+ ;
91492
+ }
91493
+
91494
+ class LocationalInteractionMetadata {
91495
+ timestamp = performance.now()
91496
+ position = new Vector2()
91497
+
91498
+ /**
91499
+ *
91500
+ * @param {Vector2} p
91501
+ */
91502
+ static from(p) {
91503
+ const r = new LocationalInteractionMetadata();
91504
+
91505
+ r.position.copy(p);
91506
+
91507
+ return r;
91508
+ }
91509
+ }
91510
+
91432
91511
  /**
91433
91512
  * @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
91434
91513
  * @see https://w3c.github.io/uievents/#widl-MouseEvent-buttons
@@ -91506,6 +91585,7 @@ function getTouchCenter(touchList, result) {
91506
91585
 
91507
91586
  }
91508
91587
 
91588
+
91509
91589
  /**
91510
91590
  *
91511
91591
  * @param {Signal} up
@@ -91514,13 +91594,49 @@ function getTouchCenter(touchList, result) {
91514
91594
  * @param {number} maxDistance
91515
91595
  * @param {Signal} signal
91516
91596
  */
91517
- function observeTap(up, down, move, maxDistance, signal) {
91597
+ function observeTap(
91598
+ up,
91599
+ down,
91600
+ move,
91601
+ maxDistance,
91602
+ signal
91603
+ ) {
91518
91604
 
91519
- const origin = new Vector2();
91605
+ /**
91606
+ *
91607
+ * @type {Map<number, LocationalInteractionMetadata>}
91608
+ */
91609
+ const active = new Map();
91610
+
91611
+ /**
91612
+ *
91613
+ * @param {number} id
91614
+ */
91615
+ function reset(id) {
91616
+
91617
+ if (active.delete(id)) {
91618
+ up.remove(handleUp);
91619
+ move.remove(handleMove);
91620
+ }
91621
+ }
91520
91622
 
91623
+ /**
91624
+ *
91625
+ * @param {Vector2} position
91626
+ * @param {MouseEvent|TouchEvent} event
91627
+ */
91521
91628
  function handleUp(position, event) {
91522
- up.remove(handleUp);
91523
- move.remove(handleMove);
91629
+ const id = eventToSourceIdentifier(event);
91630
+
91631
+ const meta = active.get(id);
91632
+
91633
+ if (meta === undefined) {
91634
+ // this should not happen
91635
+ return;
91636
+ }
91637
+
91638
+ reset(id);
91639
+
91524
91640
  signal.send2(position, event);
91525
91641
  }
91526
91642
 
@@ -91530,20 +91646,42 @@ function observeTap(up, down, move, maxDistance, signal) {
91530
91646
  * @param {MouseEvent|TouchEvent} event
91531
91647
  */
91532
91648
  function handleMove(position, event) {
91533
- if (origin.distanceTo(position) > maxDistance) {
91534
- //we moved too far, abort tap
91535
- move.remove(handleMove);
91649
+ const id = eventToSourceIdentifier(event);
91536
91650
 
91537
- up.remove(handleUp);
91651
+ const meta = active.get(id);
91652
+
91653
+ if (meta === undefined) {
91654
+ // this should not happen
91655
+
91656
+ reset(id);
91657
+
91658
+ return;
91659
+ }
91660
+
91661
+ if (meta.position.distanceTo(position) > maxDistance) {
91662
+ //we moved too far, abort tap
91663
+ reset(id);
91538
91664
  }
91665
+
91539
91666
  }
91540
91667
 
91541
- function handleDown(position) {
91668
+ /**
91669
+ *
91670
+ * @param {Vector2} position
91671
+ * @param {TouchEvent|MouseEvent} event
91672
+ */
91673
+ function handleDown(position, event) {
91674
+ const id = eventToSourceIdentifier(event);
91675
+
91676
+ // make sure to cancel previous pending resolution
91677
+ reset(id);
91678
+
91679
+ active.set(id, LocationalInteractionMetadata.from(position));
91680
+
91542
91681
  up.addOne(handleUp);
91682
+
91543
91683
  //track move
91544
91684
  move.add(handleMove);
91545
-
91546
- origin.copy(position);
91547
91685
  }
91548
91686
 
91549
91687
  down.add(handleDown);
@@ -91854,17 +91992,11 @@ class PointerDevice {
91854
91992
  this.#domElement = domElement;
91855
91993
 
91856
91994
 
91857
- this.#touchStart.add((param0, param1, param2) => {
91858
- this.on.down.send3(param0, param1, param2);
91859
- });
91995
+ this.#touchStart.add(this.on.down.send3, this.on.down);
91860
91996
 
91861
- this.#touchEnd.add((param0, param1, param2) => {
91862
- this.on.up.send3(param0, param1, param2);
91863
- });
91864
- this.#touchMove.add((param0, param1, param2) => {
91865
- this.on.move.send3(param0, param1, param2);
91866
- });
91997
+ this.#touchEnd.add(this.on.up.send3, this.on.up);
91867
91998
 
91999
+ this.#touchMove.add(this.on.move.send3, this.on.move);
91868
92000
 
91869
92001
  //constructed events
91870
92002
  observeTap(this.on.up, this.on.down, this.on.move, 10, this.on.tap);
@@ -91880,6 +92012,16 @@ class PointerDevice {
91880
92012
  });
91881
92013
  }
91882
92014
 
92015
+
92016
+ /**
92017
+ *
92018
+ * @param {TouchEvent} event
92019
+ */
92020
+ #eventHandlerGlobalTouchEnd = (event) => {
92021
+ getTouchCenter(event.touches, this.position);
92022
+ this.#globalUp.send2(this.position, event);
92023
+ }
92024
+
91883
92025
  /**
91884
92026
  *
91885
92027
  * @param {MouseEvent} event
@@ -91893,19 +92035,7 @@ class PointerDevice {
91893
92035
 
91894
92036
  const button = this.buttons[button_index];
91895
92037
 
91896
- if (button !== undefined) {
91897
- button.is_down = true;
91898
- button.down.send0();
91899
- }
91900
- }
91901
-
91902
- /**
91903
- *
91904
- * @param {TouchEvent} event
91905
- */
91906
- #eventHandlerGlobalTouchEnd = (event) => {
91907
- getTouchCenter(event.touches, this.position);
91908
- this.#globalUp.send2(this.position, event);
92038
+ button?.press();
91909
92039
  }
91910
92040
 
91911
92041
  /**
@@ -91930,10 +92060,7 @@ class PointerDevice {
91930
92060
 
91931
92061
  const button = this.buttons[button_index];
91932
92062
 
91933
- if (button !== undefined) {
91934
- button.is_down = false;
91935
- button.up.send0();
91936
- }
92063
+ button?.release();
91937
92064
  }
91938
92065
 
91939
92066
  /**
@@ -108037,7 +108164,7 @@ class MaxRectanglesPacker {
108037
108164
  return -Math.min(box.getWidth(), box.getHeight());
108038
108165
  }
108039
108166
 
108040
- const heap = new BinaryHeap(scoreBoxByMinSide);
108167
+ const heap = new FastBinaryHeap(scoreBoxByMinSide);
108041
108168
 
108042
108169
  for (let i = 0; i < numBoxes; i++) {
108043
108170
  heap.push(i);