@woosh/meep-engine 2.84.6 → 2.84.9

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 (34) hide show
  1. package/build/meep.cjs +137 -107
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +137 -107
  4. package/package.json +10 -5
  5. package/src/core/cache/LoadingCache.js +2 -1
  6. package/src/core/cache/LoadingCache.spec.js +13 -1
  7. package/src/core/collection/array/arrayIndexByEquality.js +1 -0
  8. package/src/core/collection/list/List.js +25 -17
  9. package/src/core/collection/list/List.spec.js +73 -0
  10. package/src/core/geom/3d/SurfacePoint3.js +3 -40
  11. package/src/core/geom/Vector3.js +25 -14
  12. package/src/core/model/stat/LinearModifier.spec.js +5 -6
  13. package/src/core/process/PromiseWatcher.spec.js +27 -23
  14. package/src/core/process/worker/WorkerBuilder.js +5 -1
  15. package/src/core/process/worker/WorkerProxy.js +3 -2
  16. package/src/engine/animation/behavior/animateProperty.js +4 -4
  17. package/src/engine/ecs/Entity.spec.js +33 -0
  18. package/src/engine/ecs/EntityComponentDataset.js +17 -11
  19. package/src/engine/ecs/EntityReference.js +12 -0
  20. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +1 -1
  21. package/src/engine/ecs/transform/Transform.js +1 -1
  22. package/src/engine/ecs/transform/Transform.spec.js +44 -0
  23. package/src/engine/graphics/camera/CameraShake.js +1 -127
  24. package/src/engine/graphics/camera/CameraShakeBehavior.js +91 -0
  25. package/src/engine/graphics/camera/CameraShakeTraumaBehavior.js +38 -0
  26. package/src/engine/graphics/ecs/animation/animator/AnimationGraphSystem.js +9 -23
  27. package/src/engine/graphics/ecs/animation/animator/blending/BlendStateMatrix.js +11 -6
  28. package/src/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +20 -12
  29. package/src/engine/graphics/ecs/animation/animator/graph/AnimationState.js +3 -3
  30. package/src/engine/graphics/ecs/path/tube/build/estimatePathViaIterativeIntegral.js +1 -1
  31. package/src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +6 -6
  32. package/src/engine/intelligence/behavior/ecs/SendEventBehavior.js +43 -0
  33. package/src/view/View.js +52 -30
  34. package/src/view/writeCssTransformMatrix.js +26 -0
package/build/meep.cjs CHANGED
@@ -2640,35 +2640,32 @@ let Vector3$1 = class Vector3 {
2640
2640
 
2641
2641
  /**
2642
2642
  *
2643
- * @param {ArrayList<number>|number[]|Float32Array} m4
2643
+ * @param {ArrayLike<number>|number[]|Float32Array} m4
2644
2644
  */
2645
2645
  applyMatrix4(m4) {
2646
2646
  const x = this.x;
2647
2647
  const y = this.y;
2648
2648
  const z = this.z;
2649
2649
 
2650
- const _x = m4[0] * x + m4[4] * y + m4[8] * z + m4[12];
2651
- const _y = m4[1] * x + m4[5] * y + m4[9] * z + m4[13];
2652
- const _z = m4[2] * x + m4[6] * y + m4[10] * z + m4[14];
2650
+ const w = 1 / (m4[3] * x + m4[7] * y + m4[11] * z + m4[15]);
2651
+
2652
+ const _x = (m4[0] * x + m4[4] * y + m4[8] * z + m4[12])* w;
2653
+ const _y = (m4[1] * x + m4[5] * y + m4[9] * z + m4[13])* w;
2654
+ const _z = (m4[2] * x + m4[6] * y + m4[10] * z + m4[14])* w;
2653
2655
 
2654
2656
  this.set(_x, _y, _z);
2655
2657
  }
2656
2658
 
2657
2659
  /**
2658
2660
  * Assume current vector holds a direction, transform using a matrix to produce a new directional unit vector
2659
- * @param {THREE.Matrix4} m
2661
+ * @param {ArrayLike<number>|number[]|Float32Array} m4
2660
2662
  */
2661
- transformDirection_three(m) {
2662
-
2663
- // input: THREE.Matrix4 affine matrix
2664
- // vector interpreted as a direction
2665
-
2663
+ applyDirectionMatrix4(m4){
2666
2664
  const x = this.x, y = this.y, z = this.z;
2667
- const e = m.elements;
2668
2665
 
2669
- const _x = e[0] * x + e[4] * y + e[8] * z;
2670
- const _y = e[1] * x + e[5] * y + e[9] * z;
2671
- const _z = e[2] * x + e[6] * y + e[10] * z;
2666
+ const _x = m4[0] * x + m4[4] * y + m4[8] * z;
2667
+ const _y = m4[1] * x + m4[5] * y + m4[9] * z;
2668
+ const _z = m4[2] * x + m4[6] * y + m4[10] * z;
2672
2669
 
2673
2670
  // normalize the result
2674
2671
  const _l = 1 / v3_length(_x, _y, _z);
@@ -2680,6 +2677,20 @@ let Vector3$1 = class Vector3 {
2680
2677
  );
2681
2678
  }
2682
2679
 
2680
+ /**
2681
+ * @deprecated use non-three.js version instead
2682
+ * @param {THREE.Matrix4} m
2683
+ */
2684
+ transformDirection_three(m) {
2685
+
2686
+ // input: THREE.Matrix4 affine matrix
2687
+ // vector interpreted as a direction
2688
+
2689
+ const e = m.elements;
2690
+
2691
+ this.applyDirectionMatrix4(e);
2692
+ }
2693
+
2683
2694
  /**
2684
2695
  *
2685
2696
  * @param {THREE.Matrix3} m
@@ -4743,7 +4754,7 @@ class Transform {
4743
4754
  get forward() {
4744
4755
  const result = Vector3$1.forward.clone();
4745
4756
 
4746
- result.applyMatrix4(this.matrix);
4757
+ result.applyDirectionMatrix4(this.matrix);
4747
4758
 
4748
4759
  return result;
4749
4760
  }
@@ -47191,44 +47202,8 @@ class SurfacePoint3 {
47191
47202
  */
47192
47203
  applyMatrix4(m) {
47193
47204
 
47194
- // transform position
47195
- const p = this.position;
47196
-
47197
- const p_x = p.x;
47198
- const p_y = p.y;
47199
- const p_z = p.z;
47200
-
47201
- // compute perspective projection
47202
- const w = 1 / (m[3] * p_x + m[7] * p_y + m[11] * p_z + m[15]);
47203
-
47204
- const result_p_x = (m[0] * p_x + m[4] * p_y + m[8] * p_z + m[12]) * w;
47205
- const result_p_y = (m[1] * p_x + m[5] * p_y + m[9] * p_z + m[13]) * w;
47206
- const result_p_z = (m[2] * p_x + m[6] * p_y + m[10] * p_z + m[14]) * w;
47207
-
47208
- p.set(
47209
- result_p_x,
47210
- result_p_y,
47211
- result_p_z
47212
- );
47213
-
47214
- // transform normal
47215
- const n = this.normal;
47216
-
47217
- const n_x = n.x;
47218
- const n_y = n.y;
47219
- const n_z = n.z;
47220
-
47221
- const result_n_x = m[0] * n_x + m[4] * n_y + m[8] * n_z;
47222
- const result_n_y = m[1] * n_x + m[5] * n_y + m[9] * n_z;
47223
- const result_n_z = m[2] * n_x + m[6] * n_y + m[10] * n_z;
47224
-
47225
- const normal_multiplier = 1 / v3_length(result_n_x, result_n_y, result_n_z);
47226
-
47227
- n.set(
47228
- result_n_x * normal_multiplier,
47229
- result_n_y * normal_multiplier,
47230
- result_n_z * normal_multiplier,
47231
- );
47205
+ this.position.applyMatrix4(m);
47206
+ this.normal.applyDirectionMatrix4(m);
47232
47207
  }
47233
47208
 
47234
47209
  /**
@@ -61118,6 +61093,7 @@ function objectsEqual(a, b) {
61118
61093
  }
61119
61094
 
61120
61095
  /**
61096
+ * Works similarly to `Array.prototype.indexOf`, but instead of strict equality - uses provided equality method
61121
61097
  * @template T
61122
61098
  * @param {T[]} array
61123
61099
  * @param {T} element
@@ -61221,7 +61197,7 @@ class List {
61221
61197
  this.data = array !== undefined ? array.slice() : [];
61222
61198
 
61223
61199
  /**
61224
- *
61200
+ * Number of elements in the list
61225
61201
  * @type {number}
61226
61202
  */
61227
61203
  this.length = this.data.length;
@@ -61790,30 +61766,30 @@ class List {
61790
61766
  }
61791
61767
 
61792
61768
  /**
61793
- *
61769
+ * @deprecated use `#reset` directly in combination with `this.on.removed` signal
61794
61770
  * @param {function(element:T,index:number)} callback
61795
61771
  * @param {*} [thisArg]
61796
61772
  */
61797
61773
  resetViaCallback(callback, thisArg) {
61774
+
61798
61775
  const length = this.length;
61799
- if (length > 0) {
61800
61776
 
61801
- const removed = this.on.removed;
61777
+ const removed = this.on.removed;
61802
61778
 
61803
- const oldElements = this.data;
61779
+ const data = this.data;
61804
61780
 
61805
- //only signal if there are listeners attached
61806
- for (let i = length - 1; i >= 0; i--) {
61807
- const element = oldElements[i];
61808
- // decrement data length gradually to allow handlers access to the rest of the elements
61809
- this.data.length = i;
61810
- this.length = i;
61811
- removed.send2(element, i);
61781
+ for (let i = length - 1; i >= 0; i--) {
61782
+ const element = data[i];
61812
61783
 
61813
- callback.call(thisArg, element, i);
61814
- }
61784
+ // decrement data length gradually to allow handlers access to the rest of the elements
61785
+ data.length = i;
61786
+ this.length = i;
61815
61787
 
61788
+ removed.send2(element, i);
61789
+
61790
+ callback.call(thisArg, element, i);
61816
61791
  }
61792
+
61817
61793
  }
61818
61794
 
61819
61795
  reset() {
@@ -62033,11 +62009,19 @@ class List {
62033
62009
  }
62034
62010
 
62035
62011
  /**
62036
- *
62012
+ * First element in the list
62013
+ * @returns {T|undefined}
62014
+ */
62015
+ first() {
62016
+ return this.get(0);
62017
+ }
62018
+
62019
+ /**
62020
+ * Last element in the list
62037
62021
  * @return {T|undefined}
62038
62022
  */
62039
62023
  last() {
62040
- return this.data[this.length - 1];
62024
+ return this.get(this.length - 1);
62041
62025
  }
62042
62026
 
62043
62027
  /**
@@ -63121,10 +63105,11 @@ class WorkerProxy {
63121
63105
  }
63122
63106
 
63123
63107
  /**
63108
+ * Invoke a given method on the worker, as defined by the `WorkerBuilder`
63124
63109
  * @template T
63125
- * @param {number} name
63110
+ * @param {number} name Method's name
63126
63111
  * @param {Array} args
63127
- * @return {Promise<T>}
63112
+ * @return {Promise<T>} eventual result of the invoked method
63128
63113
  */
63129
63114
  $submitRequest(name, args) {
63130
63115
  const pending = this.__pending[name];
@@ -63347,6 +63332,10 @@ class WorkerBuilder {
63347
63332
  functions = [];
63348
63333
  preamble = new LineBuilder();
63349
63334
 
63335
+ /**
63336
+ *
63337
+ * @param {string} code
63338
+ */
63350
63339
  addCode(code) {
63351
63340
  this.preamble.add(code);
63352
63341
  }
@@ -79749,28 +79738,19 @@ function m3_cm_compose_transform(
79749
79738
  }
79750
79739
 
79751
79740
  /**
79752
- * @author Alex Goldring, 2018
79753
- * @copyright Alex Goldring 2018
79741
+ * Smallest safe increment for a Float32
79742
+ * @see https://www.cplusplus.com/reference/cfloat/
79743
+ * @see https://bitbashing.io/comparing-floats.html
79744
+ * @type {number}
79754
79745
  */
79755
-
79756
-
79757
-
79758
- const scratch_m3_0 = new Float32Array(9);
79759
-
79746
+ const FLT_EPSILON_32 = 1.192092896E-7;
79747
+
79760
79748
  /**
79761
- * @see https://dev.opera.com/articles/understanding-the-css-transforms-matrix/
79762
- * @param domElement
79763
- * @param {Vector2} position
79764
- * @param {Vector2} scale
79765
- * @param {number} rotation angle in radians
79749
+ *
79750
+ * @param {Float32Array} m3
79751
+ * @param {HTMLElement} domElement
79766
79752
  */
79767
- function setElementTransform(domElement, position, scale, rotation) {
79768
-
79769
- const m3 = scratch_m3_0;
79770
-
79771
- m3_cm_compose_transform(m3, position.x, position.y, scale.x, scale.y, 0, 0, rotation);
79772
-
79773
-
79753
+ function writeCssTransformMatrix(m3, domElement) {
79774
79754
  /*
79775
79755
  * CSS matrix is:
79776
79756
  * a c e
@@ -79790,7 +79770,13 @@ function setElementTransform(domElement, position, scale, rotation) {
79790
79770
  const style = domElement.style;
79791
79771
 
79792
79772
  style.transform = transform;
79793
- }
79773
+ }
79774
+
79775
+ /**
79776
+ * @author Alex Goldring, 2018
79777
+ * @copyright Alex Goldring 2018
79778
+ */
79779
+
79794
79780
 
79795
79781
  /**
79796
79782
  *
@@ -79829,6 +79815,9 @@ const INITIAL_FLAGS = ViewFlags.Visible;
79829
79815
  * @class
79830
79816
  */
79831
79817
  class View {
79818
+ #transform_written = new Float32Array(9);
79819
+ #transform_current = new Float32Array(9);
79820
+
79832
79821
  /**
79833
79822
  * @constructor
79834
79823
  */
@@ -79853,31 +79842,32 @@ class View {
79853
79842
  this.flags = INITIAL_FLAGS;
79854
79843
 
79855
79844
  /**
79856
- *
79845
+ * @readonly
79857
79846
  * @type {Vector2}
79858
79847
  */
79859
79848
  const position = this.position = new Vector2(0, 0);
79860
79849
 
79861
79850
  /**
79862
- *
79851
+ * @readonly
79863
79852
  * @type {Vector1}
79864
79853
  */
79865
79854
  const rotation = this.rotation = new Vector1(0);
79866
79855
 
79867
79856
  /**
79868
- *
79857
+ * @readonly
79869
79858
  * @type {Vector2}
79870
79859
  */
79871
79860
  const scale = this.scale = new Vector2(1, 1);
79872
79861
 
79873
79862
  /**
79874
- *
79863
+ * @readonly
79875
79864
  * @type {Vector2}
79876
79865
  */
79877
79866
  const size = this.size = new Vector2(0, 0);
79878
79867
 
79879
79868
  /**
79880
79869
  * Origin from which rotation and scaling is applied
79870
+ * @readonly
79881
79871
  * @type {Vector2}
79882
79872
  */
79883
79873
  this.transformOrigin = new Vector2(0.5, 0.5);
@@ -80015,7 +80005,41 @@ class View {
80015
80005
  * @private
80016
80006
  */
80017
80007
  __updateTransform() {
80018
- setElementTransform(this.el, this.position, this.scale, this.rotation.getValue());
80008
+ const position = this.position;
80009
+ const scale = this.scale;
80010
+ const rotation = this.rotation.getValue();
80011
+
80012
+ m3_cm_compose_transform(this.#transform_current, position.x, position.y, scale.x, scale.y, 0, 0, rotation);
80013
+
80014
+ this.#tryWriteTransform();
80015
+ }
80016
+
80017
+ #tryWriteTransform() {
80018
+
80019
+ const current = this.#transform_current;
80020
+ const written = this.#transform_written;
80021
+
80022
+ for (let i = 0; i < 9; i++) {
80023
+ const a = current[i];
80024
+ const b = written[i];
80025
+
80026
+ if (epsilonEquals(a, b, FLT_EPSILON_32)) {
80027
+ // common path
80028
+ continue;
80029
+ }
80030
+
80031
+ this.#writeTransform();
80032
+ return true;
80033
+
80034
+ }
80035
+
80036
+ return false;
80037
+ }
80038
+
80039
+ #writeTransform() {
80040
+ writeCssTransformMatrix(this.#transform_current, this.el);
80041
+
80042
+ this.#transform_written.set(this.#transform_current);
80019
80043
  }
80020
80044
 
80021
80045
  /**
@@ -93079,10 +93103,10 @@ class EntityComponentDataset {
93079
93103
 
93080
93104
  /**
93081
93105
  *
93082
- * @param {number} entityIndex
93106
+ * @param {number} entity_id
93083
93107
  */
93084
- removeEntity(entityIndex) {
93085
- if (!this.entityExists(entityIndex)) {
93108
+ removeEntity(entity_id) {
93109
+ if (!this.entityExists(entity_id)) {
93086
93110
  // entity doesn't exist
93087
93111
  return;
93088
93112
  }
@@ -93090,26 +93114,31 @@ class EntityComponentDataset {
93090
93114
  const componentOccupancy = this.componentOccupancy;
93091
93115
  const typeCount = this.componentTypeCount;
93092
93116
 
93093
- const occupancyStart = entityIndex * typeCount;
93117
+ const occupancyStart = entity_id * typeCount;
93094
93118
  const occupancyEnd = occupancyStart + typeCount;
93095
93119
 
93096
- for (let i = componentOccupancy.nextSetBit(occupancyStart); i < occupancyEnd && i !== -1; i = componentOccupancy.nextSetBit(i + 1)) {
93120
+ // remove all components from the entity
93121
+ for (
93122
+ let i = componentOccupancy.nextSetBit(occupancyStart);
93123
+ i < occupancyEnd && i !== -1;
93124
+ i = componentOccupancy.nextSetBit(i + 1)
93125
+ ) {
93097
93126
  const componentIndex = i % typeCount;
93098
- this.removeComponentFromEntityByIndex_Unchecked(entityIndex, componentIndex, i);
93127
+ this.removeComponentFromEntityByIndex_Unchecked(entity_id, componentIndex, i);
93099
93128
  }
93100
93129
 
93101
93130
  //dispatch event
93102
- this.sendEvent(entityIndex, EventType.EntityRemoved, entityIndex);
93131
+ this.sendEvent(entity_id, EventType.EntityRemoved, entity_id);
93103
93132
 
93104
93133
  //purge all event listeners
93105
- delete this.__entityEventListeners[entityIndex];
93106
- delete this.__entityAnyEventListeners[entityIndex];
93134
+ delete this.__entityEventListeners[entity_id];
93135
+ delete this.__entityAnyEventListeners[entity_id];
93107
93136
 
93108
- this.entityOccupancy.set(entityIndex, false);
93137
+ this.entityOccupancy.set(entity_id, false);
93109
93138
 
93110
93139
  this.entityCount--;
93111
93140
 
93112
- this.onEntityRemoved.send1(entityIndex);
93141
+ this.onEntityRemoved.send1(entity_id);
93113
93142
  }
93114
93143
 
93115
93144
  /**
@@ -93159,6 +93188,7 @@ class EntityComponentDataset {
93159
93188
  }
93160
93189
 
93161
93190
  /**
93191
+ * This method doesn't perform any checks, make sure you understand what you are doing when using it
93162
93192
  * @private
93163
93193
  * @param {number} entityIndex
93164
93194
  * @param {number} componentIndex