@woosh/meep-engine 2.47.31 → 2.47.33

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.
package/build/meep.cjs CHANGED
@@ -60435,11 +60435,13 @@ class MapEntry {
60435
60435
  * @param {number} hash
60436
60436
  */
60437
60437
  constructor(key, value, hash) {
60438
+
60438
60439
  /**
60439
60440
  *
60440
60441
  * @type {K}
60441
60442
  */
60442
60443
  this.key = key;
60444
+
60443
60445
  /**
60444
60446
  *
60445
60447
  * @type {V}
@@ -60451,6 +60453,7 @@ class MapEntry {
60451
60453
  * @type {number}
60452
60454
  */
60453
60455
  this.hash = hash;
60456
+
60454
60457
  }
60455
60458
  }
60456
60459
 
@@ -60466,6 +60469,13 @@ const DEFAULT_INITIAL_CAPACITY = 16;
60466
60469
  */
60467
60470
  const DEFAULT_LOAD_FACTOR = 0.75;
60468
60471
 
60472
+ /**
60473
+ * Multiply previous size by this number when growing the table
60474
+ * @readonly
60475
+ * @type {number}
60476
+ */
60477
+ const GROWTH_FACTOR = 2;
60478
+
60469
60479
  /**
60470
60480
  * Implements part of {@link Map} interface
60471
60481
  * @copyright Alex Goldring (c) 2023
@@ -60490,7 +60500,9 @@ class HashMap {
60490
60500
  assert.isFunction(keyHashFunction, 'keyHashFunction');
60491
60501
  assert.isFunction(keyEqualityFunction, 'keyEqualityFunction');
60492
60502
  assert.isNonNegativeInteger(capacity, 'capacity');
60503
+
60493
60504
  assert.isNumber(loadFactor, 'loadFactor');
60505
+ assert.greaterThan(loadFactor, 0, 'loadFactor must be > 0');
60494
60506
 
60495
60507
  /**
60496
60508
  *
@@ -60603,6 +60615,8 @@ class HashMap {
60603
60615
  * @private
60604
60616
  */
60605
60617
  __compute_bucket_index(hash) {
60618
+ assert.isInteger(hash, 'hash');
60619
+
60606
60620
  // mix the input hash to minimize potential impact of poor hash function spread
60607
60621
  const mixed_hash = (hash >>> 16) ^ hash;
60608
60622
 
@@ -60666,18 +60680,19 @@ class HashMap {
60666
60680
 
60667
60681
  }
60668
60682
 
60669
- bucket.push(new MapEntry(key, value,raw_hash));
60683
+ bucket.push(new MapEntry(key, value, raw_hash));
60670
60684
 
60671
60685
  const old_size = this.size;
60672
60686
  const new_size = old_size + 1;
60673
60687
  this.size = new_size;
60674
60688
 
60675
60689
  // compute actual current load
60676
- const load = new_size / this.__bucket_count;
60690
+ const bucket_count = this.__bucket_count;
60691
+ const load = new_size / bucket_count;
60677
60692
 
60678
60693
  if (load > this.__load_factor) {
60679
60694
  // current load is too high, increase table size
60680
- this.setBucketCount(this.__bucket_count * 2);
60695
+ this.setBucketCount(bucket_count * GROWTH_FACTOR);
60681
60696
  }
60682
60697
  }
60683
60698
 
@@ -60802,8 +60817,11 @@ class HashMap {
60802
60817
  /**
60803
60818
  *
60804
60819
  * @param {function(message:string, key:K, value:V)} callback
60820
+ * @param {*} [thisArg]
60821
+ * @returns {boolean}
60805
60822
  */
60806
- verifyHashes(callback) {
60823
+ verifyHashes(callback, thisArg) {
60824
+ let all_hashes_valid = true;
60807
60825
 
60808
60826
  let h, i;
60809
60827
 
@@ -60829,15 +60847,25 @@ class HashMap {
60829
60847
  //check hash
60830
60848
  const raw_hash = this.keyHashFunction(entry.key);
60831
60849
 
60850
+ if (entry.hash !== raw_hash) {
60851
+ callback.call(thisArg, `Hash stored on the entry(=${entry.hash}) is different from the computed key hash(=${raw_hash}).`, entry.key, entry.value);
60852
+
60853
+ all_hashes_valid = false;
60854
+ }
60855
+
60832
60856
  const actual_bucket_index = this.__compute_bucket_index(raw_hash);
60833
60857
 
60834
60858
  const stored_bucket_index = parseInt(h);
60835
60859
 
60836
60860
  if (actual_bucket_index !== stored_bucket_index) {
60837
- callback(`Hash of key has changed. old=${stored_bucket_index}, new=${actual_bucket_index}`, entry.key, entry.value);
60861
+ callback.call(thisArg, `Hash of key has changed. old=${stored_bucket_index}, new=${actual_bucket_index}`, entry.key, entry.value);
60862
+
60863
+ all_hashes_valid = false;
60838
60864
  }
60839
60865
  }
60840
60866
  }
60867
+
60868
+ return all_hashes_valid;
60841
60869
  }
60842
60870
 
60843
60871
  /**
@@ -61501,6 +61529,18 @@ class Cache {
61501
61529
 
61502
61530
  this.weight = 0;
61503
61531
  }
61532
+
61533
+ /**
61534
+ *
61535
+ * @param {function(message:string, key:Key, value:Value)} callback
61536
+ * @param {*} [thisArg]
61537
+ * @returns {boolean}
61538
+ */
61539
+ validate(callback, thisArg) {
61540
+ return this.data.verifyHashes((msg, key, entry) => {
61541
+ callback.call(thisArg, msg, key, entry.value);
61542
+ });
61543
+ }
61504
61544
  }
61505
61545
 
61506
61546
  /**
@@ -77811,6 +77851,24 @@ class StaticMaterialCache {
77811
77851
  return material;
77812
77852
 
77813
77853
  }
77854
+
77855
+ /**
77856
+ *
77857
+ * @param {function(string)} error_consumer
77858
+ * @param {*} [thisArg]
77859
+ * @returns {boolean}
77860
+ */
77861
+ validate(error_consumer, thisArg) {
77862
+ const materials_valid = this.materialCache.validate((message, key, value) => {
77863
+ error_consumer.call(thisArg, `Material error: ${message}. Material ${key}`);
77864
+ });
77865
+ const textures_valid = this.textureCache.validate((message, key, value) => {
77866
+ error_consumer.call(thisArg, `Texture error: ${message}. Texture ${key}`);
77867
+ });
77868
+
77869
+ return materials_valid
77870
+ && textures_valid;
77871
+ }
77814
77872
  }
77815
77873
 
77816
77874
  /**
@@ -78463,42 +78521,90 @@ class InstancedMeshGroup {
78463
78521
  }
78464
78522
  }
78465
78523
 
78524
+ class SGCacheKey {
78525
+ geometry = -1;
78526
+ material = -1;
78527
+ /**
78528
+ *
78529
+ * @type {DrawMode}
78530
+ */
78531
+ mode = DrawMode.Triangles;
78532
+
78533
+ flags = 0;
78534
+
78535
+ hash(){
78536
+ return this.geometry ^ this.material;
78537
+ }
78538
+
78539
+ /**
78540
+ *
78541
+ * @param {SGCacheKey} other
78542
+ * @returns {boolean}
78543
+ */
78544
+ equals(other){
78545
+ return this.geometry === other.geometry
78546
+ && this.material === other.material
78547
+ && this.mode === other.mode
78548
+ && this.flags === other.flags;
78549
+ }
78550
+
78551
+ /**
78552
+ *
78553
+ * @param {SGCacheKey} other
78554
+ */
78555
+ copy(other){
78556
+ this.geometry = other.geometry;
78557
+ this.material = other.material;
78558
+ this.mode = other.mode;
78559
+ this.flags = other.flags;
78560
+ }
78561
+
78562
+ clone(){
78563
+ const r = new SGCacheKey();
78564
+
78565
+ r.copy(this);
78566
+
78567
+ return r;
78568
+ }
78569
+
78570
+ /**
78571
+ *
78572
+ * @param {ShadedGeometry} sg
78573
+ */
78574
+ fromSG(sg){
78575
+ this.geometry = sg.geometry.id;
78576
+ this.material = sg.material.id;
78577
+ this.mode = sg.mode;
78578
+ this.flags = sg.flags;
78579
+ }
78580
+ }
78581
+
78466
78582
  const INSTANCED_EQUALITY_FLAGS = ShadedGeometryFlags.CastShadow
78467
78583
  | ShadedGeometryFlags.ReceiveShadow
78468
78584
  ;
78469
78585
 
78586
+ /**
78587
+ * @readonly
78588
+ * @type {SGCacheKey}
78589
+ */
78590
+ const scratch_key = new SGCacheKey();
78591
+
78470
78592
  class InstancedRendererAdapter extends AbstractRenderAdapter {
78471
- constructor() {
78472
- super();
78473
78593
 
78474
- /**
78475
- *
78476
- * @type {HashMap<ShadedGeometry, InstancedMeshGroup>}
78477
- * @private
78478
- */
78479
- this.__instanced_meshes = new HashMap({
78480
- keyHashFunction(sg) {
78481
- return sg.geometry.id
78482
- ^ sg.material.id
78483
- ^ sg.mode
78484
- ;
78485
- },
78486
- keyEqualityFunction(a, b) {
78487
- return a.material.id === b.material.id
78488
- && a.geometry.id === b.geometry.id
78489
- && a.mode === b.mode
78490
- && (a.flags & INSTANCED_EQUALITY_FLAGS) === (b.flags & INSTANCED_EQUALITY_FLAGS)
78491
- ;
78492
- }
78493
- });
78594
+ /**
78595
+ *
78596
+ * @type {HashMap<SGCacheKey, InstancedMeshGroup>}
78597
+ * @private
78598
+ */
78599
+ __instanced_meshes = new HashMap();
78600
+
78601
+ /**
78602
+ *
78603
+ * @type {Set<InstancedMeshGroup>}
78604
+ * @private
78605
+ */
78606
+ __active_meshes = new Set();
78494
78607
 
78495
- /**
78496
- *
78497
- * @type {Set<InstancedMeshGroup>}
78498
- * @private
78499
- */
78500
- this.__active_meshes = new Set();
78501
- }
78502
78608
 
78503
78609
  score(geometry, material, instance_count) {
78504
78610
  if (instance_count > 16) {
@@ -78517,7 +78623,12 @@ class InstancedRendererAdapter extends AbstractRenderAdapter {
78517
78623
  * @private
78518
78624
  */
78519
78625
  __get_instanced_mesh(sg) {
78520
- let im = this.__instanced_meshes.get(sg);
78626
+ scratch_key.fromSG(sg);
78627
+
78628
+ // mask out some flags
78629
+ scratch_key.flags &= INSTANCED_EQUALITY_FLAGS;
78630
+
78631
+ let im = this.__instanced_meshes.get(scratch_key);
78521
78632
 
78522
78633
 
78523
78634
  if (im !== undefined) {
@@ -78538,7 +78649,7 @@ class InstancedRendererAdapter extends AbstractRenderAdapter {
78538
78649
  im.mesh.castShadow = sg.getFlag(ShadedGeometryFlags.CastShadow);
78539
78650
  im.mesh.receiveShadow = sg.getFlag(ShadedGeometryFlags.ReceiveShadow);
78540
78651
 
78541
- this.__instanced_meshes.set(sg, im);
78652
+ this.__instanced_meshes.set(scratch_key.clone(), im);
78542
78653
 
78543
78654
  return im;
78544
78655
 
@@ -78590,8 +78701,8 @@ class InstancedRendererAdapter extends AbstractRenderAdapter {
78590
78701
 
78591
78702
  const meshes = this.__active_meshes;
78592
78703
 
78593
- for (const activeMesh of meshes) {
78594
- activeMesh.setCount(0);
78704
+ for (const mesh of meshes) {
78705
+ mesh.setCount(0);
78595
78706
  }
78596
78707
 
78597
78708
  meshes.clear();