@woosh/meep-engine 2.61.0 → 2.62.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.
Files changed (36) hide show
  1. package/build/meep.cjs +234 -212
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +234 -212
  4. package/package.json +1 -1
  5. package/src/core/bvh2/BinaryNode.js +16 -13
  6. package/src/core/bvh2/LeafNode.js +6 -3
  7. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +81 -0
  8. package/src/core/geom/3d/aabb/AABB3.js +24 -36
  9. package/src/core/geom/3d/aabb/aabb3_array_compute_from_sphere.js +22 -0
  10. package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere.js +22 -0
  11. package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere_array.js +11 -0
  12. package/src/core/geom/3d/aabb/aabb3_signed_distance_to_aabb3.js +28 -0
  13. package/src/core/geom/3d/aabb/serializeAABB3Quantized16Uint.js +19 -10
  14. package/src/core/geom/3d/tetrahedra/delaunay/Cavity.js +3 -4
  15. package/src/engine/ecs/foliage/ecs/Foliage2System.js +3 -0
  16. package/src/engine/ecs/foliage/ecs/InstancedMeshComponent.js +4 -1
  17. package/src/engine/ecs/foliage/ecs/convertInstancedMeshComponents2Entities.js +64 -0
  18. package/src/engine/ecs/foliage/ecs/{InstancedMeshUtils.js → optimizeIndividualMeshesEntitiesToInstances.js} +11 -70
  19. package/src/engine/graphics/camera/testClippingPlaneComputation.js +25 -27
  20. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +49 -52
  21. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +40 -42
  22. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +43 -25
  23. package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +10 -6
  24. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +37 -41
  25. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +44 -46
  26. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +24 -26
  27. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +40 -42
  28. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +36 -38
  29. package/src/engine/graphics/shadows/testShadowMapRendering.js +19 -19
  30. package/src/engine/sound/dB2Volume.js +8 -0
  31. package/src/engine/sound/ecs/emitter/SoundEmitter.js +125 -99
  32. package/src/engine/sound/ecs/emitter/SoundEmitterComponentContext.js +4 -42
  33. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +31 -121
  34. package/src/engine/sound/volume2dB.js +8 -0
  35. package/src/generation/theme/ThemeEngine.js +19 -53
  36. package/src/engine/graphics/geometry/bvh/buffered/BVHFromBufferGeometry.js +0 -133
package/build/meep.cjs CHANGED
@@ -49816,6 +49816,95 @@ function array_quick_sort_by_comparator(
49816
49816
  }
49817
49817
  }
49818
49818
 
49819
+ /**
49820
+ *
49821
+ * @param {number} x0
49822
+ * @param {number} y0
49823
+ * @param {number} z0
49824
+ * @param {number} x1
49825
+ * @param {number} y1
49826
+ * @param {number} z1
49827
+ * @returns {number}
49828
+ */
49829
+ function aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1) {
49830
+ const dx = x1 - x0;
49831
+ const dy = y1 - y0;
49832
+ const dz = z1 - z0;
49833
+ return dy * (dx + dz) + dz * dx; //1 side, since it's a heuristic only
49834
+ }
49835
+
49836
+ /**
49837
+ *
49838
+ * @param {AABB3} node
49839
+ * @returns {number}
49840
+ */
49841
+ function aabb3_box_surface_area_2(node) {
49842
+ return aabb3_compute_half_surface_area(node.x0, node.y0, node.z0, node.x1, node.y1, node.z1);
49843
+ }
49844
+
49845
+ /**
49846
+ *
49847
+ * @param {AABB3} a
49848
+ * @param {AABB3} b
49849
+ * @returns {number}
49850
+ */
49851
+ function aabb3_combined_surface_area(a, b) {
49852
+ const x0 = min2(a.x0, b.x0);
49853
+ const y0 = min2(a.y0, b.y0);
49854
+ const z0 = min2(a.z0, b.z0);
49855
+
49856
+ const x1 = max2(a.x1, b.x1);
49857
+ const y1 = max2(a.y1, b.y1);
49858
+ const z1 = max2(a.z1, b.z1);
49859
+
49860
+ return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
49861
+ }
49862
+
49863
+ /**
49864
+ * Returns true if two 1D lines intersect, touch is treated as intersection
49865
+ * Parameters are assumed to be ordered, a1 >= a0, b1 >= b0
49866
+ * @param {Number} a0
49867
+ * @param {Number} a1
49868
+ * @param {Number} b0
49869
+ * @param {Number} b1
49870
+ * @returns {boolean}
49871
+ */
49872
+ function intersects1D(a0, a1, b0, b1) {
49873
+ assert.isNumber(a0, "a0");
49874
+ assert.isNumber(a1, "a1");
49875
+ assert.isNumber(b0, "b0");
49876
+ assert.isNumber(b1, "b1");
49877
+
49878
+ return a1 >= b0 && b1 >= a0;
49879
+ }
49880
+
49881
+ /**
49882
+ *
49883
+ * @param {number} ax0
49884
+ * @param {number} ay0
49885
+ * @param {number} az0
49886
+ * @param {number} ax1
49887
+ * @param {number} ay1
49888
+ * @param {number} az1
49889
+ * @param {number} bx0
49890
+ * @param {number} by0
49891
+ * @param {number} bz0
49892
+ * @param {number} bx1
49893
+ * @param {number} by1
49894
+ * @param {number} bz1
49895
+ * @returns {boolean}
49896
+ */
49897
+ function aabb3_intersects_aabb3(
49898
+ ax0, ay0, az0,
49899
+ ax1, ay1, az1,
49900
+ bx0, by0, bz0,
49901
+ bx1, by1, bz1
49902
+ ) {
49903
+ return intersects1D(ax0, ax1, bx0, bx1)
49904
+ && intersects1D(ay0, ay1, by0, by1)
49905
+ && intersects1D(az0, az1, bz0, bz1);
49906
+ }
49907
+
49819
49908
  /**
49820
49909
  *
49821
49910
  * @param {number[]} values
@@ -49902,6 +49991,73 @@ function mortonEncode_magicbits(x, y, z) {
49902
49991
  return x_bits | y_bits | z_bits;
49903
49992
  }
49904
49993
 
49994
+ //
49995
+
49996
+ /**
49997
+ *
49998
+ * @param {ArrayLike<number>|number[]|AABB3} aabb
49999
+ * @param {number} x
50000
+ * @param {number} y
50001
+ * @param {number} z
50002
+ * @return {boolean}
50003
+ */
50004
+ function aabb3_array_intersects_point(
50005
+ aabb,
50006
+ x, y, z
50007
+ ) {
50008
+ return x >= aabb[0]
50009
+ && x <= aabb[3]
50010
+ && y >= aabb[1]
50011
+ && y <= aabb[4]
50012
+ && z >= aabb[2]
50013
+ && z <= aabb[5];
50014
+ }
50015
+
50016
+ /**
50017
+ *
50018
+ * @param {number[]|Float32Array|Float64Array} destination
50019
+ * @param {number} destination_offset
50020
+ * @param {number} x0
50021
+ * @param {number} y0
50022
+ * @param {number} z0
50023
+ * @param {number} x1
50024
+ * @param {number} y1
50025
+ * @param {number} z1
50026
+ */
50027
+ function aabb3_build_corners(destination, destination_offset, x0, y0, z0, x1, y1, z1) {
50028
+ destination[destination_offset] = x0;
50029
+ destination[destination_offset + 1] = y0;
50030
+ destination[destination_offset + 2] = z0;
50031
+
50032
+ destination[destination_offset + 3] = x1;
50033
+ destination[destination_offset + 4] = y0;
50034
+ destination[destination_offset + 5] = z0;
50035
+
50036
+ destination[destination_offset + 6] = x0;
50037
+ destination[destination_offset + 7] = y1;
50038
+ destination[destination_offset + 8] = z0;
50039
+
50040
+ destination[destination_offset + 9] = x1;
50041
+ destination[destination_offset + 10] = y1;
50042
+ destination[destination_offset + 11] = z0;
50043
+
50044
+ destination[destination_offset + 12] = x0;
50045
+ destination[destination_offset + 13] = y0;
50046
+ destination[destination_offset + 14] = z1;
50047
+
50048
+ destination[destination_offset + 15] = x1;
50049
+ destination[destination_offset + 16] = y0;
50050
+ destination[destination_offset + 17] = z1;
50051
+
50052
+ destination[destination_offset + 18] = x0;
50053
+ destination[destination_offset + 19] = y1;
50054
+ destination[destination_offset + 20] = z1;
50055
+
50056
+ destination[destination_offset + 21] = x1;
50057
+ destination[destination_offset + 22] = y1;
50058
+ destination[destination_offset + 23] = z1;
50059
+ }
50060
+
49905
50061
  /**
49906
50062
  * Distance of the farthest point along the plane normal from the plane. If the result is >= 0, at least a portion of AABB pokes above the plane
49907
50063
  * @param {number} plane_normal_x
@@ -50016,47 +50172,53 @@ function aabb3_compute_plane_side(
50016
50172
 
50017
50173
  /**
50018
50174
  *
50019
- * @param {number[]|Float32Array|Float64Array} destination
50020
- * @param {number} destination_offset
50021
50175
  * @param {number} x0
50022
50176
  * @param {number} y0
50023
50177
  * @param {number} z0
50024
50178
  * @param {number} x1
50025
50179
  * @param {number} y1
50026
50180
  * @param {number} z1
50181
+ * @returns {number}
50027
50182
  */
50028
- function aabb3_build_corners(destination, destination_offset, x0, y0, z0, x1, y1, z1) {
50029
- destination[destination_offset] = x0;
50030
- destination[destination_offset + 1] = y0;
50031
- destination[destination_offset + 2] = z0;
50032
-
50033
- destination[destination_offset + 3] = x1;
50034
- destination[destination_offset + 4] = y0;
50035
- destination[destination_offset + 5] = z0;
50036
-
50037
- destination[destination_offset + 6] = x0;
50038
- destination[destination_offset + 7] = y1;
50039
- destination[destination_offset + 8] = z0;
50183
+ function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
50184
+ const dx = x1 - x0;
50185
+ const dy = y1 - y0;
50186
+ const dz = z1 - z0;
50187
+ return (dy * (dx + dz) + dz * dx) * 2; //2 of each side
50188
+ }
50189
+
50190
+ /**
50191
+ *
50192
+ * @param {number} x0
50193
+ * @param {number} y0
50194
+ * @param {number} z0
50195
+ * @param {number} x1
50196
+ * @param {number} y1
50197
+ * @param {number} z1
50198
+ * @param {ArrayLike<number>|number[]|Float32Array|Float64Array} frustum
50199
+ * @return {boolean}
50200
+ */
50201
+ function aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum) {
50202
+ for (let i = 0; i < 24; i += 4) {
50040
50203
 
50041
- destination[destination_offset + 9] = x1;
50042
- destination[destination_offset + 10] = y1;
50043
- destination[destination_offset + 11] = z0;
50204
+ const plane_x = frustum[i];
50205
+ const plane_y = frustum[i + 1];
50206
+ const plane_z = frustum[i + 2];
50207
+ const plane_w = frustum[i + 3];
50044
50208
 
50045
- destination[destination_offset + 12] = x0;
50046
- destination[destination_offset + 13] = y0;
50047
- destination[destination_offset + 14] = z1;
50209
+ const plane_distance = aabb3_compute_distance_above_plane_max(
50210
+ plane_x, plane_y, plane_z, plane_w,
50211
+ x0, y0, z0,
50212
+ x1, y1, z1
50213
+ );
50048
50214
 
50049
- destination[destination_offset + 15] = x1;
50050
- destination[destination_offset + 16] = y0;
50051
- destination[destination_offset + 17] = z1;
50215
+ if (plane_distance < 0) {
50216
+ return false;
50217
+ }
50052
50218
 
50053
- destination[destination_offset + 18] = x0;
50054
- destination[destination_offset + 19] = y1;
50055
- destination[destination_offset + 20] = z1;
50219
+ }
50056
50220
 
50057
- destination[destination_offset + 21] = x1;
50058
- destination[destination_offset + 22] = y1;
50059
- destination[destination_offset + 23] = z1;
50221
+ return true;
50060
50222
  }
50061
50223
 
50062
50224
  //
@@ -50276,57 +50438,6 @@ function aabb3_intersects_ray(
50276
50438
  return f2 <= extents_x * abs_direction_y + extents_y * abs_direction_x;
50277
50439
  }
50278
50440
 
50279
- /**
50280
- *
50281
- * @param {number} x0
50282
- * @param {number} y0
50283
- * @param {number} z0
50284
- * @param {number} x1
50285
- * @param {number} y1
50286
- * @param {number} z1
50287
- * @returns {number}
50288
- */
50289
- function aabb3_compute_surface_area(x0, y0, z0, x1, y1, z1) {
50290
- const dx = x1 - x0;
50291
- const dy = y1 - y0;
50292
- const dz = z1 - z0;
50293
- return (dy * (dx + dz) + dz * dx) * 2; //2 of each side
50294
- }
50295
-
50296
- /**
50297
- *
50298
- * @param {number} x0
50299
- * @param {number} y0
50300
- * @param {number} z0
50301
- * @param {number} x1
50302
- * @param {number} y1
50303
- * @param {number} z1
50304
- * @param {ArrayLike<number>|number[]|Float32Array|Float64Array} frustum
50305
- * @return {boolean}
50306
- */
50307
- function aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum) {
50308
- for (let i = 0; i < 24; i += 4) {
50309
-
50310
- const plane_x = frustum[i];
50311
- const plane_y = frustum[i + 1];
50312
- const plane_z = frustum[i + 2];
50313
- const plane_w = frustum[i + 3];
50314
-
50315
- const plane_distance = aabb3_compute_distance_above_plane_max(
50316
- plane_x, plane_y, plane_z, plane_w,
50317
- x0, y0, z0,
50318
- x1, y1, z1
50319
- );
50320
-
50321
- if (plane_distance < 0) {
50322
- return false;
50323
- }
50324
-
50325
- }
50326
-
50327
- return true;
50328
- }
50329
-
50330
50441
  /**
50331
50442
  * NOTE: Based on Transforming Axis-Aligned Bounding Boxes by Jim Arvo from "Graphics Gems", Academic Press, 1990
50332
50443
  * NOTE: {@link result} and {@link aabb} must be different objects
@@ -50409,26 +50520,33 @@ function aabb3_signed_distance_sqr_to_point(
50409
50520
  }
50410
50521
  }
50411
50522
 
50412
- //
50523
+ function aabb3_signed_distance_to_aabb3(
50524
+ ax0,ay0,az0,ax1,ay1,az1,
50525
+ bx0,by0,bz0, bx1,by1,bz1
50526
+ ){
50413
50527
 
50414
- /**
50415
- *
50416
- * @param {ArrayLike<number>|number[]|AABB3} aabb
50417
- * @param {number} x
50418
- * @param {number} y
50419
- * @param {number} z
50420
- * @return {boolean}
50421
- */
50422
- function aabb3_array_intersects_point(
50423
- aabb,
50424
- x, y, z
50425
- ) {
50426
- return x >= aabb[0]
50427
- && x <= aabb[3]
50428
- && y >= aabb[1]
50429
- && y <= aabb[4]
50430
- && z >= aabb[2]
50431
- && z <= aabb[5];
50528
+ //do projection
50529
+ const xp0 = bx0 - ax1;
50530
+ const xp1 = ax0 - bx1;
50531
+ const yp0 = by0 - ay1;
50532
+ const yp1 = ay0 - by1;
50533
+ const zp0 = bz0 - az1;
50534
+ const zp1 = az0 - bz1;
50535
+
50536
+ //calculate separation in each axis
50537
+ const dx = Math.max(xp0, xp1);
50538
+ const dy = Math.max(yp0, yp1);
50539
+ const dz = Math.max(zp0, zp1);
50540
+
50541
+ //straight-line distance
50542
+ let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
50543
+
50544
+ if (dx < 0 && dy < 0 && dz < 0) {
50545
+ //penetration
50546
+ return -distance;
50547
+ } else {
50548
+ return distance;
50549
+ }
50432
50550
  }
50433
50551
 
50434
50552
  /**
@@ -50437,6 +50555,7 @@ function aabb3_array_intersects_point(
50437
50555
 
50438
50556
  /**
50439
50557
  * Axis-Aligned bounding box in 3D
50558
+ * NOTE: In cases where all you want is raw performance - prefer to use typed arrays instead along with `aabb3_` functions
50440
50559
  */
50441
50560
  class AABB3 {
50442
50561
  /**
@@ -50656,7 +50775,12 @@ class AABB3 {
50656
50775
  * @returns {boolean}
50657
50776
  */
50658
50777
  _equals(x0, y0, z0, x1, y1, z1) {
50659
- return this.x0 === x0 && this.y0 === y0 && this.z0 === z0 && this.x1 === x1 && this.y1 === y1 && this.z1 === z1;
50778
+ return this.x0 === x0
50779
+ && this.y0 === y0
50780
+ && this.z0 === z0
50781
+ && this.x1 === x1
50782
+ && this.y1 === y1
50783
+ && this.z1 === z1;
50660
50784
  }
50661
50785
 
50662
50786
  /**
@@ -50750,28 +50874,10 @@ class AABB3 {
50750
50874
  const _y1 = this.y1;
50751
50875
  const _z1 = this.z1;
50752
50876
 
50753
- //do projection
50754
- const xp0 = _x0 - x1;
50755
- const xp1 = x0 - _x1;
50756
- const yp0 = _y0 - y1;
50757
- const yp1 = y0 - _y1;
50758
- const zp0 = _z0 - z1;
50759
- const zp1 = z0 - _z1;
50760
-
50761
- //calculate separation in each axis
50762
- const dx = Math.max(xp0, xp1);
50763
- const dy = Math.max(yp0, yp1);
50764
- const dz = Math.max(zp0, zp1);
50765
-
50766
- //straight-line distance
50767
- let distance = Math.sqrt(dx * dx + dy * dy + dz * dz);
50768
-
50769
- if (dx < 0 && dy < 0 && dz < 0) {
50770
- //penetration
50771
- return -distance;
50772
- } else {
50773
- return distance;
50774
- }
50877
+ return aabb3_signed_distance_to_aabb3(
50878
+ _x0, _y0, _z0, _x1, _y1, _z1,
50879
+ x0, y0, z0, x1, y1, z1
50880
+ );
50775
50881
  }
50776
50882
 
50777
50883
  /**
@@ -51196,7 +51302,6 @@ class AABB3 {
51196
51302
  }
51197
51303
 
51198
51304
  /**
51199
- *
51200
51305
  * @param {Plane[]} clippingPlanes
51201
51306
  * @returns {boolean}
51202
51307
  */
@@ -51491,6 +51596,9 @@ function isLeaf(node) {
51491
51596
  return node.isLeafNode;
51492
51597
  }
51493
51598
 
51599
+ /**
51600
+ * @deprecated use {@link ExplicitBinaryBoundingVolumeHierarchy} and {@link EBBVHLeafProxy} respectively
51601
+ */
51494
51602
  class LeafNode extends Node {
51495
51603
  /**
51496
51604
  *
@@ -51701,95 +51809,6 @@ function traverseBinaryNodeUsingVisitor(node, visitor) {
51701
51809
  stackPointer$3 = stackOffset;
51702
51810
  }
51703
51811
 
51704
- /**
51705
- * Returns true if two 1D lines intersect, touch is treated as intersection
51706
- * Parameters are assumed to be ordered, a1 >= a0, b1 >= b0
51707
- * @param {Number} a0
51708
- * @param {Number} a1
51709
- * @param {Number} b0
51710
- * @param {Number} b1
51711
- * @returns {boolean}
51712
- */
51713
- function intersects1D(a0, a1, b0, b1) {
51714
- assert.isNumber(a0, "a0");
51715
- assert.isNumber(a1, "a1");
51716
- assert.isNumber(b0, "b0");
51717
- assert.isNumber(b1, "b1");
51718
-
51719
- return a1 >= b0 && b1 >= a0;
51720
- }
51721
-
51722
- /**
51723
- *
51724
- * @param {number} ax0
51725
- * @param {number} ay0
51726
- * @param {number} az0
51727
- * @param {number} ax1
51728
- * @param {number} ay1
51729
- * @param {number} az1
51730
- * @param {number} bx0
51731
- * @param {number} by0
51732
- * @param {number} bz0
51733
- * @param {number} bx1
51734
- * @param {number} by1
51735
- * @param {number} bz1
51736
- * @returns {boolean}
51737
- */
51738
- function aabb3_intersects_aabb3(
51739
- ax0, ay0, az0,
51740
- ax1, ay1, az1,
51741
- bx0, by0, bz0,
51742
- bx1, by1, bz1
51743
- ) {
51744
- return intersects1D(ax0, ax1, bx0, bx1)
51745
- && intersects1D(ay0, ay1, by0, by1)
51746
- && intersects1D(az0, az1, bz0, bz1);
51747
- }
51748
-
51749
- /**
51750
- *
51751
- * @param {number} x0
51752
- * @param {number} y0
51753
- * @param {number} z0
51754
- * @param {number} x1
51755
- * @param {number} y1
51756
- * @param {number} z1
51757
- * @returns {number}
51758
- */
51759
- function aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1) {
51760
- const dx = x1 - x0;
51761
- const dy = y1 - y0;
51762
- const dz = z1 - z0;
51763
- return dy * (dx + dz) + dz * dx; //1 side, since it's a heuristic only
51764
- }
51765
-
51766
- /**
51767
- *
51768
- * @param {AABB3} node
51769
- * @returns {number}
51770
- */
51771
- function aabb3_box_surface_area_2(node) {
51772
- return aabb3_compute_half_surface_area(node.x0, node.y0, node.z0, node.x1, node.y1, node.z1);
51773
- }
51774
-
51775
- /**
51776
- *
51777
- * @param {AABB3} a
51778
- * @param {AABB3} b
51779
- * @returns {number}
51780
- */
51781
- function aabb3_combined_surface_area(a, b) {
51782
- const x0 = min2(a.x0, b.x0);
51783
- const y0 = min2(a.y0, b.y0);
51784
- const z0 = min2(a.z0, b.z0);
51785
-
51786
- const x1 = max2(a.x1, b.x1);
51787
- const y1 = max2(a.y1, b.y1);
51788
- const z1 = max2(a.z1, b.z1);
51789
-
51790
- return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
51791
- }
51792
-
51793
51812
  /**
51794
51813
  * Created by Alex on 17/11/2014.
51795
51814
  */
@@ -51813,6 +51832,9 @@ let stackPointer$2 = 0;
51813
51832
  */
51814
51833
  const stack$9 = [];
51815
51834
 
51835
+ /**
51836
+ * @deprecated use {@link ExplicitBinaryBoundingVolumeHierarchy} instead
51837
+ */
51816
51838
  class BinaryNode extends Node {
51817
51839
  constructor() {
51818
51840
  super();