@woosh/meep-engine 2.119.16 → 2.119.19

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 (95) hide show
  1. package/README.md +2 -4
  2. package/build/bundle-worker-image-decoder.js +1 -1
  3. package/package.json +1 -1
  4. package/src/core/binary/BinaryBuffer.d.ts +2 -6
  5. package/src/core/binary/BinaryBuffer.d.ts.map +1 -1
  6. package/src/core/binary/BinaryBuffer.js +7 -8
  7. package/src/core/binary/BitSet.d.ts.map +1 -1
  8. package/src/core/binary/BitSet.js +2 -3
  9. package/src/core/bvh2/bvh3/BVH.d.ts.map +1 -1
  10. package/src/core/bvh2/bvh3/BVH.js +8 -0
  11. package/src/core/cache/FrequencySketch.js +1 -1
  12. package/src/core/codegen/LineBuilder.d.ts +7 -1
  13. package/src/core/codegen/LineBuilder.d.ts.map +1 -1
  14. package/src/core/codegen/LineBuilder.js +10 -1
  15. package/src/core/geom/2d/convex-hull/fixed_convex_hull_relaxation.d.ts.map +1 -1
  16. package/src/core/geom/2d/convex-hull/fixed_convex_hull_relaxation.js +1 -0
  17. package/src/core/geom/3d/Ray3.d.ts +12 -0
  18. package/src/core/geom/3d/Ray3.d.ts.map +1 -1
  19. package/src/core/geom/3d/Ray3.js +32 -0
  20. package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
  21. package/src/core/geom/3d/aabb/AABB3.js +17 -7
  22. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.d.ts +2 -2
  23. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.d.ts.map +1 -1
  24. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.js +11 -11
  25. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
  26. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +2 -1
  27. package/src/core/geom/3d/tetrahedra/bvh/tetrahedral_mesh_to_bvh.d.ts +8 -0
  28. package/src/core/geom/3d/tetrahedra/bvh/tetrahedral_mesh_to_bvh.d.ts.map +1 -0
  29. package/src/core/geom/3d/tetrahedra/bvh/tetrahedral_mesh_to_bvh.js +36 -0
  30. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_compute_tet_aabb3.d.ts +10 -0
  31. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_compute_tet_aabb3.d.ts.map +1 -0
  32. package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_compute_tet_aabb3.js +49 -0
  33. package/src/core/geom/random/randomPointInCircle.d.ts +3 -2
  34. package/src/core/geom/random/randomPointInCircle.d.ts.map +1 -1
  35. package/src/core/geom/random/randomPointInCircle.js +6 -3
  36. package/src/core/geom/vec2/v2_magnitude.d.ts +3 -5
  37. package/src/core/geom/vec2/v2_magnitude.d.ts.map +1 -1
  38. package/src/core/geom/vec2/v2_magnitude.js +3 -8
  39. package/src/core/graph/v2/NodeContainer.d.ts.map +1 -1
  40. package/src/core/graph/v2/NodeContainer.js +3 -9
  41. package/src/core/lang/reactive/AbstractCachingParser.d.ts +8 -5
  42. package/src/core/lang/reactive/AbstractCachingParser.d.ts.map +1 -1
  43. package/src/core/lang/reactive/AbstractCachingParser.js +19 -24
  44. package/src/core/lang/reactive/pegjs/ReactivePegParser.d.ts +2 -1
  45. package/src/core/lang/reactive/pegjs/ReactivePegParser.d.ts.map +1 -1
  46. package/src/core/localization/Localization.js +1 -1
  47. package/src/core/model/reactive/model/ReactiveBinaryExpression.d.ts.map +1 -1
  48. package/src/core/model/reactive/model/ReactiveBinaryExpression.js +17 -21
  49. package/src/core/model/reactive/model/ReactiveUnaryExpression.d.ts +1 -1
  50. package/src/core/model/reactive/model/ReactiveUnaryExpression.d.ts.map +1 -1
  51. package/src/core/model/reactive/model/ReactiveUnaryExpression.js +10 -10
  52. package/src/core/model/reactive/model/arithmetic/ReactiveNegate.d.ts.map +1 -1
  53. package/src/core/model/reactive/model/logic/ReactiveNot.d.ts.map +1 -1
  54. package/src/engine/achievements/AchievementGateway.d.ts.map +1 -1
  55. package/src/engine/achievements/AchievementGateway.js +1 -1
  56. package/src/engine/achievements/AchievementManager.d.ts +1 -1
  57. package/src/engine/achievements/AchievementManager.d.ts.map +1 -1
  58. package/src/engine/achievements/AchievementManager.js +16 -30
  59. package/src/engine/achievements/gateway/StorageAchievementGateway.d.ts.map +1 -1
  60. package/src/engine/achievements/gateway/StorageAchievementGateway.js +14 -9
  61. package/src/engine/ecs/EntityComponentDataset.d.ts.map +1 -1
  62. package/src/engine/ecs/EntityComponentDataset.js +5 -2
  63. package/src/engine/ecs/EntityReference.d.ts +6 -0
  64. package/src/engine/ecs/EntityReference.d.ts.map +1 -1
  65. package/src/engine/ecs/EntityReference.js +16 -1
  66. package/src/engine/ecs/storage/BinaryBufferDeSerializer.js +1 -1
  67. package/src/engine/graphics/sh3/prototypeSH3Probe.js +1 -1
  68. package/src/engine/graphics/texture/virtual/VirtualTextureTileLoader.d.ts +10 -0
  69. package/src/engine/graphics/texture/virtual/VirtualTextureTileLoader.d.ts.map +1 -1
  70. package/src/engine/graphics/texture/virtual/VirtualTextureTileLoader.js +39 -19
  71. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts +8 -0
  72. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts.map +1 -1
  73. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.js +8 -1
  74. package/src/engine/graphics/texture/virtual/VirtualTextureUsageUpdater.d.ts.map +1 -1
  75. package/src/engine/graphics/texture/virtual/VirtualTextureUsageUpdater.js +2 -1
  76. package/src/engine/intelligence/behavior/composite/SequenceBehavior.d.ts.map +1 -1
  77. package/src/engine/intelligence/behavior/composite/SequenceBehavior.js +17 -5
  78. package/src/engine/intelligence/behavior/ecs/BehaviorComponent.d.ts.map +1 -1
  79. package/src/engine/intelligence/behavior/ecs/BehaviorComponent.js +22 -54
  80. package/src/engine/intelligence/behavior/ecs/DieBehavior.d.ts.map +1 -1
  81. package/src/engine/intelligence/behavior/ecs/DieBehavior.js +2 -7
  82. package/src/engine/intelligence/behavior/ecs/SendEventBehavior.d.ts +4 -0
  83. package/src/engine/intelligence/behavior/ecs/SendEventBehavior.d.ts.map +1 -1
  84. package/src/engine/intelligence/behavior/ecs/SendEventBehavior.js +8 -7
  85. package/src/engine/intelligence/behavior/ecs/WaitForEventBehavior.d.ts.map +1 -1
  86. package/src/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +21 -22
  87. package/src/core/bvh2/bvh3/query/cache/BVH_QUERY_CACHE_SIZE.d.ts +0 -2
  88. package/src/core/bvh2/bvh3/query/cache/BVH_QUERY_CACHE_SIZE.d.ts.map +0 -1
  89. package/src/core/bvh2/bvh3/query/cache/BVH_QUERY_CACHE_SIZE.js +0 -1
  90. package/src/core/bvh2/bvh3/query/cache/bvh_query_cache_hash_v3.d.ts +0 -9
  91. package/src/core/bvh2/bvh3/query/cache/bvh_query_cache_hash_v3.d.ts.map +0 -1
  92. package/src/core/bvh2/bvh3/query/cache/bvh_query_cache_hash_v3.js +0 -31
  93. package/src/core/geom/2d/lt-grid/LooseTightGrid.d.ts +0 -55
  94. package/src/core/geom/2d/lt-grid/LooseTightGrid.d.ts.map +0 -1
  95. package/src/core/geom/2d/lt-grid/LooseTightGrid.js +0 -221
@@ -1,31 +1,28 @@
1
1
  import { assert } from "../../../../core/assert.js";
2
- import { ClockChannelType } from "./ClockChannelType.js";
3
2
  import { RepeatBehavior } from "../decorator/RepeatBehavior.js";
4
3
  import { ActionBehavior } from "../primitive/ActionBehavior.js";
5
- import { SequenceBehavior } from "../composite/SequenceBehavior.js";
4
+ import { ClockChannelType } from "./ClockChannelType.js";
6
5
 
7
6
  export class BehaviorComponent {
8
- constructor() {
9
-
10
- /**
11
- * What clock should be used for ticking associated behavior
12
- * @type {ClockChannelType|number}
13
- */
14
- this.clock = ClockChannelType.Simulation;
15
-
16
- /**
17
- *
18
- * @type {number}
19
- */
20
- this.flags = 0;
21
-
22
- /**
23
- *
24
- * @type {Behavior|null}
25
- * @private
26
- */
27
- this.__behavior = null;
28
- }
7
+
8
+ /**
9
+ * What clock should be used for ticking associated behavior
10
+ * @type {ClockChannelType|number}
11
+ */
12
+ clock = ClockChannelType.Simulation;
13
+
14
+ /**
15
+ *
16
+ * @type {number}
17
+ */
18
+ flags = 0;
19
+
20
+ /**
21
+ *
22
+ * @type {Behavior|null}
23
+ * @private
24
+ */
25
+ __behavior = null;
29
26
 
30
27
  /**
31
28
  *
@@ -83,35 +80,6 @@ export class BehaviorComponent {
83
80
  this.__behavior = v;
84
81
  }
85
82
 
86
- /**
87
- * @deprecated
88
- * @returns {Readonly<Behavior[]>}
89
- */
90
- get list() {
91
- if (this.__behavior !== null) {
92
- return [this.__behavior];
93
- } else {
94
- return [];
95
- }
96
- }
97
-
98
- /**
99
- * @deprecated
100
- * @param {Behavior[]} v
101
- */
102
- set list(v) {
103
- console.warn('.list is deprecated, use SequenceBehavior instead');
104
- if (v.length > 1) {
105
- console.warn('.list is deprecated, converting to sequence instead');
106
- this.__behavior = SequenceBehavior.from(v);
107
- } else if (v.length === 1) {
108
- this.__behavior = v[0];
109
- } else {
110
- this.__behavior = null;
111
- }
112
- }
113
-
114
-
115
83
  /**
116
84
  *
117
85
  * @param {function(timeDelta:number)} f
@@ -130,8 +98,8 @@ export class BehaviorComponent {
130
98
  * @returns {BehaviorComponent}
131
99
  */
132
100
  static fromOne(b) {
133
- assert.defined(b, 'behavior');
134
- assert.notNull(b, 'behavior');
101
+ assert.defined(b, 'behavior');
102
+ assert.notNull(b, 'behavior');
135
103
  assert.equal(b.isBehavior, true, 'b.isBehavior !== true');
136
104
 
137
105
  const result = new BehaviorComponent();
@@ -1 +1 @@
1
- {"version":3,"file":"DieBehavior.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/intelligence/behavior/ecs/DieBehavior.js"],"names":[],"mappings":"AAGA;IAGI,6BAEC;IAED,qCAcC;CACJ;+BAzB8B,qBAAqB;+BACrB,sBAAsB"}
1
+ {"version":3,"file":"DieBehavior.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/intelligence/behavior/ecs/DieBehavior.js"],"names":[],"mappings":"AAGA;IAGI,6BAEC;IAED,qCASC;CACJ;+BAnB8B,qBAAqB;+BADrB,sBAAsB"}
@@ -1,5 +1,5 @@
1
- import { EntityBehavior } from "./EntityBehavior.js";
2
1
  import { BehaviorStatus } from "../BehaviorStatus.js";
2
+ import { EntityBehavior } from "./EntityBehavior.js";
3
3
 
4
4
  export class DieBehavior extends EntityBehavior {
5
5
 
@@ -13,14 +13,9 @@ export class DieBehavior extends EntityBehavior {
13
13
  const entity = this.entity;
14
14
  const ecd = this.ecd;
15
15
 
16
- if (!ecd.entityExists(entity)) {
17
- //entity doesn't exist, count as success
18
-
19
- return BehaviorStatus.Succeeded;
20
- }
21
-
22
16
  ecd.removeEntity(entity);
23
17
 
24
18
  return BehaviorStatus.Succeeded;
19
+
25
20
  }
26
21
  }
@@ -1,5 +1,9 @@
1
1
  export class SendEventBehavior extends EntityBehavior {
2
2
  static fromJSON(j: any): SendEventBehavior;
3
+ /**
4
+ * ID of the event
5
+ * @type {string}
6
+ */
3
7
  event: string;
4
8
  data: {};
5
9
  target: number;
@@ -1 +1 @@
1
- {"version":3,"file":"SendEventBehavior.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/intelligence/behavior/ecs/SendEventBehavior.js"],"names":[],"mappings":"AAIA;IAiBI,2CAMC;IAnBG,cAAe;IACf,SAAc;IACd,eAAgB;IAGpB;;;;aAMC;IAcD,qCAQC;CACJ;+BAxC8B,qBAAqB;+BADrB,sBAAsB"}
1
+ {"version":3,"file":"SendEventBehavior.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/intelligence/behavior/ecs/SendEventBehavior.js"],"names":[],"mappings":"AAIA;IAkBI,2CAMC;IAtBD;;;OAGG;IACH,OAFU,MAAM,CAEL;IACX,SAAU;IACV,eAAY;IAEZ;;;;aAMC;IAcD,qCAQC;CACJ;+BAzC8B,qBAAqB;+BADrB,sBAAsB"}
@@ -3,16 +3,17 @@ import { BehaviorStatus } from "../BehaviorStatus.js";
3
3
  import { EntityBehavior } from "./EntityBehavior.js";
4
4
 
5
5
  export class SendEventBehavior extends EntityBehavior {
6
- constructor() {
7
- super();
8
6
 
9
- this.event = "";
10
- this.data = {};
11
- this.target = -1;
12
- }
7
+ /**
8
+ * ID of the event
9
+ * @type {string}
10
+ */
11
+ event = "";
12
+ data = {};
13
+ target = -1;
13
14
 
14
15
  fromJSON({ event, data = {}, target = -1 }) {
15
- assert.typeOf(event, 'string', 'event');
16
+ assert.isString(event, 'event');
16
17
 
17
18
  this.event = event;
18
19
  this.data = data;
@@ -1 +1 @@
1
- {"version":3,"file":"WaitForEventBehavior.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/intelligence/behavior/ecs/WaitForEventBehavior.js"],"names":[],"mappings":"AAIA;IA8BI;;;;OAIG;IACH,4BAFY,oBAAoB,CAQ/B;IArCG;;;OAGG;IACH,OAFU,MAAM,CAED;IAEf;;;OAGG;IACH,UAFU,OAAO,CAEI;IAErB;;;OAGG;IACH,QAFU,MAAM,CAEA;IAGpB;;;aAKC;IAeD,wEAMC;IAED;;OAEG;IACH,iBAIC;CAoBJ;;kBAIS,MAAM;;+BAtFe,qBAAqB;+BACrB,sBAAsB"}
1
+ {"version":3,"file":"WaitForEventBehavior.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/intelligence/behavior/ecs/WaitForEventBehavior.js"],"names":[],"mappings":"AAIA;IA6BI;;;;OAIG;IACH,4BAFY,oBAAoB,CAQ/B;IArCD;;;OAGG;IACH,OAFU,MAAM,CAEL;IAEX;;;OAGG;IACH,UAFU,OAAO,CAEA;IAEjB;;;OAGG;IACH,QAFU,MAAM,CAEJ;IAGZ;;;aAKC;IAeD,wEAMC;IAED;;OAEG;IACH,iBAIC;CAoBJ;;kBAIS,MAAM;;+BAnFe,qBAAqB;+BADrB,sBAAsB"}
@@ -1,29 +1,28 @@
1
- import { EntityBehavior } from "./EntityBehavior.js";
2
- import { BehaviorStatus } from "../BehaviorStatus.js";
3
1
  import { assert } from "../../../../core/assert.js";
2
+ import { BehaviorStatus } from "../BehaviorStatus.js";
3
+ import { EntityBehavior } from "./EntityBehavior.js";
4
4
 
5
5
  export class WaitForEventBehavior extends EntityBehavior {
6
- constructor() {
7
- super();
8
-
9
- /**
10
- * Event name
11
- * @type {string}
12
- */
13
- this.event = "";
14
-
15
- /**
16
- *
17
- * @type {boolean}
18
- */
19
- this.detected = false;
20
6
 
21
- /**
22
- * Entity to listen event on
23
- * @type {number}
24
- */
25
- this.target = -1;
26
- }
7
+
8
+ /**
9
+ * Event name
10
+ * @type {string}
11
+ */
12
+ event = "";
13
+
14
+ /**
15
+ *
16
+ * @type {boolean}
17
+ */
18
+ detected = false;
19
+
20
+ /**
21
+ * Entity to listen event on
22
+ * @type {number}
23
+ */
24
+ target = -1;
25
+
27
26
 
28
27
  fromJSON({ event, target = -1 }) {
29
28
  assert.isString(event, 'event');
@@ -1,2 +0,0 @@
1
- export const BVH_QUERY_CACHE_SIZE: number;
2
- //# sourceMappingURL=BVH_QUERY_CACHE_SIZE.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BVH_QUERY_CACHE_SIZE.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/bvh2/bvh3/query/cache/BVH_QUERY_CACHE_SIZE.js"],"names":[],"mappings":"AAAA,0CAA0C"}
@@ -1 +0,0 @@
1
- export const BVH_QUERY_CACHE_SIZE = 2**12;
@@ -1,9 +0,0 @@
1
- /**
2
- *
3
- * @param {number} x
4
- * @param {number} y
5
- * @param {number} z
6
- * @returns {number}
7
- */
8
- export function bvh_query_cache_hash_v3(x: number, y: number, z: number): number;
9
- //# sourceMappingURL=bvh_query_cache_hash_v3.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bvh_query_cache_hash_v3.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/bvh2/bvh3/query/cache/bvh_query_cache_hash_v3.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,2CALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAuBlB"}
@@ -1,31 +0,0 @@
1
- import { BVH_QUERY_CACHE_SIZE } from "./BVH_QUERY_CACHE_SIZE.js";
2
-
3
- /**
4
- *
5
- * @param {number} x
6
- * @param {number} y
7
- * @param {number} z
8
- * @returns {number}
9
- */
10
- export function bvh_query_cache_hash_v3(x, y, z) {
11
-
12
- //
13
- // const i0 = computeHashFloat(x);
14
- // const i1 = computeHashFloat(y);
15
- // const i2 = computeHashFloat(z);
16
- //
17
- // const key = ((i0 * 0xB5297A4D) ^ (i1 * 0x68E31DA4) ^ (i2 * 0x1B56C4E9))
18
- // & (BVH_QUERY_CACHE_SIZE - 1);
19
-
20
- const s = 16;
21
-
22
- const i0 = x*s;
23
- const i1 = y*s;
24
- const i2 = z*s;
25
-
26
- const key = ((i0 * 73856093) ^ (i1 * 19349663) ^ (i2 * 83492791))
27
- & (BVH_QUERY_CACHE_SIZE - 1);
28
-
29
- // convert to unsigned
30
- return key >>> 0;
31
- }
@@ -1,55 +0,0 @@
1
- /**
2
- *
3
- * NOTE: THIS CODE IS UNFINISHED, IT IS ONLY A SKETCH
4
- * TODO finish implementation
5
- *
6
- * Inspired by Makyen's post on stackoverflow: https://stackoverflow.com/a/48384354
7
- * Core idea is to have dynamically-sized bounding volumes that contain our AABBs, and then have a grid-aligned index that stores pointers to these volumes
8
- * Makyren called it "Loose/Tight Double-Grid", where "loose" refers to dynamic bounding volumes and tight refers to the grid
9
- *
10
- * Invariants:
11
- * - An element inserted into the structure will belong to exactly one "loose" cell
12
- *
13
- */
14
- export class LooseTightGrid {
15
- /**
16
- *
17
- * @param {number} v
18
- */
19
- set grid_scale(arg: number);
20
- /**
21
- *
22
- * @returns {number}
23
- */
24
- get grid_scale(): number;
25
- /**
26
- *
27
- * @param {number} size_x
28
- * @param {number} size_y
29
- */
30
- resize(size_x: number, size_y: number): void;
31
- /**
32
- *
33
- * @param {number} x
34
- * @param {number} y
35
- * @returns {number}
36
- */
37
- cell_position_to_index(x: number, y: number): number;
38
- /**
39
- *
40
- * @param {number[]} out
41
- * @param {number} out_offset
42
- * @param {number} index
43
- */
44
- cell_index_to_position(out: number[], out_offset: number, index: number): void;
45
- allocate_datum(): void;
46
- insert(): void;
47
- /**
48
- * Rebuild structure from ground-up
49
- * This is an expensive operation
50
- * Generally you'll never want to call it explicitly, it is used internally when underlying structure changes
51
- */
52
- rebuild(): void;
53
- #private;
54
- }
55
- //# sourceMappingURL=LooseTightGrid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LooseTightGrid.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/2d/lt-grid/LooseTightGrid.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;;;GAYG;AACH;IAcI;;;OAGG;IACH,4BAYC;IAED;;;OAGG;IACH,yBAEC;IAED;;;;OAIG;IACH,eAHW,MAAM,UACN,MAAM,QAehB;IAED;;;;;OAKG;IACH,0BAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAUlB;IAED;;;;;OAKG;IACH,4BAJW,MAAM,EAAE,cACR,MAAM,SACN,MAAM,QAOhB;IAED,uBAEC;IAED,eAEC;IAwDD;;;;OAIG;IACH,gBAgCC;;CAEJ"}
@@ -1,221 +0,0 @@
1
- import { assert } from "../../../assert.js";
2
- import { de_interleave_2_bits } from "../../../binary/de_interleave_2_bits.js";
3
- import { split_by_2 } from "../../../binary/split_by_2.js";
4
- import { UINT32_MAX } from "../../../binary/UINT32_MAX.js";
5
- import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
6
- import { BinaryElementPool } from "../../3d/topology/struct/binary/BinaryElementPool.js";
7
-
8
- const NULL_POINTER = UINT32_MAX;
9
-
10
- const COLUMN_PARENT = 0;
11
- const COLUMN_CHILD_1 = 1;
12
- const COLUMN_CHILD_2 = 2;
13
- const COLUMN_HEIGHT = 3;
14
- const COLUMN_AABB_OFFSET = 4;
15
-
16
- const COLUMN_USER_DATA = COLUMN_CHILD_2;
17
-
18
- /**
19
- *
20
- * NOTE: THIS CODE IS UNFINISHED, IT IS ONLY A SKETCH
21
- * TODO finish implementation
22
- *
23
- * Inspired by Makyen's post on stackoverflow: https://stackoverflow.com/a/48384354
24
- * Core idea is to have dynamically-sized bounding volumes that contain our AABBs, and then have a grid-aligned index that stores pointers to these volumes
25
- * Makyren called it "Loose/Tight Double-Grid", where "loose" refers to dynamic bounding volumes and tight refers to the grid
26
- *
27
- * Invariants:
28
- * - An element inserted into the structure will belong to exactly one "loose" cell
29
- *
30
- */
31
- export class LooseTightGrid {
32
-
33
- #resolution_x = 0
34
- #resolution_y = 0
35
-
36
- // amount of space covered by a single grid cell
37
- #grid_scale = 1
38
-
39
- #node_pool = new BinaryElementPool(10 * 4)
40
- #grid_data = new Uint32Array(0);
41
-
42
- constructor() {
43
- }
44
-
45
- /**
46
- *
47
- * @param {number} v
48
- */
49
- set grid_scale(v) {
50
- assert.isNumber(v, 'v');
51
- assert.greaterThan(v, 0, 'v');
52
-
53
- if (this.#grid_scale === v) {
54
- // no change
55
- return;
56
- }
57
-
58
- this.#grid_scale = v;
59
-
60
- this.rebuild();
61
- }
62
-
63
- /**
64
- *
65
- * @returns {number}
66
- */
67
- get grid_scale() {
68
- return this.#grid_scale;
69
- }
70
-
71
- /**
72
- *
73
- * @param {number} size_x
74
- * @param {number} size_y
75
- */
76
- resize(size_x, size_y) {
77
- assert.isNonNegativeInteger(size_x, 'size_x');
78
- assert.isNonNegativeInteger(size_y, 'size_y');
79
-
80
- if (this.#resolution_x === size_x && this.#resolution_y === size_y) {
81
- // no change
82
- return;
83
- }
84
-
85
- this.#resolution_x = size_x;
86
- this.#resolution_y = size_y;
87
-
88
- this.rebuild();
89
- }
90
-
91
- /**
92
- *
93
- * @param {number} x
94
- * @param {number} y
95
- * @returns {number}
96
- */
97
- cell_position_to_index(x, y) {
98
- assert.isNonNegativeInteger(x, 'x');
99
- assert.isNonNegativeInteger(y, 'y');
100
-
101
- const _x = split_by_2(x);
102
- const _y = split_by_2(y);
103
-
104
- return _x | (_y << 1);
105
- }
106
-
107
- /**
108
- *
109
- * @param {number[]} out
110
- * @param {number} out_offset
111
- * @param {number} index
112
- */
113
- cell_index_to_position(out, out_offset, index) {
114
-
115
- out[out_offset] = de_interleave_2_bits(index)
116
- out[out_offset + 1] = de_interleave_2_bits(index >> 1)
117
-
118
- }
119
-
120
- allocate_datum() {
121
-
122
- }
123
-
124
- insert() {
125
-
126
- }
127
-
128
- /**
129
- *
130
- * @param {number} node
131
- */
132
- #node_is_leaf(node) {
133
- const address = this.#node_pool.element_word(node);
134
-
135
- return this.#node_pool.data_uint32[address + COLUMN_CHILD_1] === NULL_POINTER;
136
- }
137
-
138
- /**
139
- * Collect leaves and de-allocate all intermediate nodes
140
- * @param {number[]} output
141
- * @param {number} output_offset
142
- * @param {number} node
143
- */
144
- #erase_tree_structure(output, output_offset, node) {
145
- const pool = this.#node_pool;
146
-
147
- const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
148
- const top = SCRATCH_UINT32_TRAVERSAL_STACK.pointer;
149
-
150
- stack[stack.pointer++] = node;
151
-
152
- let result_count = 0;
153
-
154
- while (stack.pointer > top) {
155
-
156
- stack.pointer--;
157
-
158
- const n = stack[stack.pointer];
159
-
160
- const node_address = pool.element_word(n);
161
-
162
- const child_1 = pool.data_uint32[node_address + COLUMN_CHILD_1];
163
- const child_2 = pool.data_uint32[node_address + COLUMN_CHILD_2];
164
-
165
- if (child_1 === NULL_POINTER) {
166
- // leaf node
167
- output[output_offset + result_count] = n;
168
- result_count++;
169
- } else {
170
- // binary node
171
- stack[stack.pointer++] = child_2;
172
- stack[stack.pointer++] = child_1;
173
-
174
- // de-allocate node
175
- pool.release(n);
176
- }
177
- }
178
-
179
- return result_count;
180
- }
181
-
182
- /**
183
- * Rebuild structure from ground-up
184
- * This is an expensive operation
185
- * Generally you'll never want to call it explicitly, it is used internally when underlying structure changes
186
- */
187
- rebuild() {
188
- //TODO implement
189
-
190
- let leaf_count = 0;
191
- const leaf_nodes = [];
192
- // traverse previous grid
193
- for (let i = 0; i < this.#grid_data.length; i++) {
194
- const node = this.#grid_data[i];
195
-
196
- if (node === NULL_POINTER) {
197
- // empty grid cell
198
- continue;
199
- }
200
-
201
- leaf_count += this.#erase_tree_structure(leaf_nodes, leaf_count, node);
202
- }
203
-
204
-
205
- const resolution_y = this.#resolution_y;
206
- const resolution_x = this.#resolution_x;
207
-
208
- const grid_cell_count = resolution_x * resolution_y;
209
-
210
- if (grid_cell_count !== this.#grid_data.length) {
211
- this.#grid_data = new Uint32Array(grid_cell_count);
212
- }
213
-
214
- // drop all roots
215
- this.#grid_data.fill(NULL_POINTER);
216
-
217
- // re-insert all leaves
218
-
219
- }
220
-
221
- }