@woosh/meep-engine 2.158.0 → 2.159.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.
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
7
7
  "type": "module",
8
8
  "author": "Alexander Goldring",
9
- "version": "2.158.0",
9
+ "version": "2.159.0",
10
10
  "main": "build/meep.module.js",
11
11
  "module": "build/meep.module.js",
12
12
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"BitSet.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/BitSet.js"],"names":[],"mappings":"AAiCA;;;;;;;;;;;;;;GAcG;AACH;IAslBI;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAQlB;IA/lBD;;;OAGG;IACH,+BAFW,MAAM,EAgChB;IA3BG;;;;OAIG;IACH,iBAAiB;IAEjB;;;;;OAKG;IACH,mBAA4C;IAE5C;;;;OAIG;IACH,sBAA0D;IAE1D;;;OAGG;IACH,gBAFU,MAAM,CAE2B;IAG/C;;;;OAIG;IACH,iBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,mBAFW,MAAM,QAOhB;IACD;;;;;;OAMG;IACH,uBAJW,MAAM,GAEJ,IAAI,CAUhB;IAED;;;;OAIG;IACH,QAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,iBAsBC;IAED;;;OAGG;IACH,uBAMC;IAED;;;;;OAKG;IACH,oBAyBC;IAED;;;;OAIG;IACH,2BAHW,MAAM,GACJ,MAAM,CAuClB;IAED;;;;OAIG;IACH,uBAHW,MAAM,GACJ,MAAM,CAuDlB;IAED;;;;OAIG;IACH,yBAHW,MAAM,GACJ,MAAM,CAkDlB;IAED;;;;;OAKG;IACH,eAJW,MAAM,SACN,OAAO,GACL,IAAI,CAmChB;IAED;;;OAGG;IACH,iBAFW,MAAM,QAIhB;IAED;;;;OAIG;IACH,sBAHW,MAAM,aACN,MAAM,QAWhB;IAED;;;;OAIG;IACH,wBAHW,MAAM,aACN,MAAM,QAShB;IAED;;;;OAIG;IACH,qBAFa,OAAO,CAkBnB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,OAAO,CAUnB;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,OAAO,CAUnB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,eACN,MAAM,aACN,MAAM,QAShB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,eACN,MAAM,aACN,MAAM,QAShB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,eACN,MAAM,aACN,MAAM,QAQhB;IAED;;OAEG;IACH,cAgBC;IAED;;;;OAIG;IACH,eAFa,MAAM,CA+BlB;IAED;;;OAGG;IACH,YAFW,MAAM,QAoChB;CAcJ"}
1
+ {"version":3,"file":"BitSet.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/BitSet.js"],"names":[],"mappings":"AAiCA;;;;;;;;;;;;;;GAcG;AACH;IA2lBI;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAQlB;IApmBD;;;OAGG;IACH,+BAFW,MAAM,EAgChB;IA3BG;;;;OAIG;IACH,iBAAiB;IAEjB;;;;;OAKG;IACH,mBAA4C;IAE5C;;;;OAIG;IACH,sBAA0D;IAE1D;;;OAGG;IACH,gBAFU,MAAM,CAE2B;IAG/C;;;;OAIG;IACH,iBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,mBAFW,MAAM,QAOhB;IACD;;;;;;OAMG;IACH,uBAJW,MAAM,GAEJ,IAAI,CAUhB;IAED;;;;OAIG;IACH,QAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,iBAsBC;IAED;;;OAGG;IACH,uBAMC;IAED;;;;;OAKG;IACH,oBAyBC;IAED;;;;OAIG;IACH,2BAHW,MAAM,GACJ,MAAM,CAuClB;IAED;;;;OAIG;IACH,uBAHW,MAAM,GACJ,MAAM,CAuDlB;IAED;;;;OAIG;IACH,yBAHW,MAAM,GACJ,MAAM,CAuDlB;IAED;;;;;OAKG;IACH,eAJW,MAAM,SACN,OAAO,GACL,IAAI,CAmChB;IAED;;;OAGG;IACH,iBAFW,MAAM,QAIhB;IAED;;;;OAIG;IACH,sBAHW,MAAM,aACN,MAAM,QAWhB;IAED;;;;OAIG;IACH,wBAHW,MAAM,aACN,MAAM,QAShB;IAED;;;;OAIG;IACH,qBAFa,OAAO,CAkBnB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,OAAO,CAUnB;IAED;;;;OAIG;IACH,mBAHW,MAAM,GACJ,OAAO,CAUnB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,eACN,MAAM,aACN,MAAM,QAShB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,eACN,MAAM,aACN,MAAM,QAShB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,eACN,MAAM,aACN,MAAM,QAQhB;IAED;;OAEG;IACH,cAgBC;IAED;;;;OAIG;IACH,eAFa,MAAM,CA+BlB;IAED;;;OAGG;IACH,YAFW,MAAM,QAoChB;CAcJ"}
@@ -368,7 +368,12 @@ export class BitSet {
368
368
 
369
369
  }
370
370
 
371
- return set_length;
371
+ // Bits at or beyond __length are implicitly clear. When from_index
372
+ // is word-aligned and lies at or beyond __length, both the masked
373
+ // first-word branch and the scan loop are skipped — returning
374
+ // set_length alone would violate the "first clear bit >= from_index"
375
+ // contract by returning a value smaller than from_index.
376
+ return Math.max(set_length, from_index);
372
377
  }
373
378
 
374
379
  /**
@@ -1,7 +1,10 @@
1
1
  /**
2
+ * Quantize a [0, 1] float to a byte. Out-of-range input saturates: every caller is a
3
+ * color/channel packer, where wrapping would turn 1.004 into 0 (near-white to black) and
4
+ * negatives into arbitrary mid-range values.
2
5
  *
3
6
  * @param {number} v
4
- * @returns {number}
7
+ * @returns {number} integer in [0, 255]
5
8
  */
6
9
  export function float_to_uint8(v: number): number;
7
10
  //# sourceMappingURL=float_to_uint8.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"float_to_uint8.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/float_to_uint8.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,kCAHW,MAAM,GACJ,MAAM,CAIlB"}
1
+ {"version":3,"file":"float_to_uint8.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/float_to_uint8.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,kCAHW,MAAM,GACJ,MAAM,CAMlB"}
@@ -1,8 +1,13 @@
1
1
  /**
2
+ * Quantize a [0, 1] float to a byte. Out-of-range input saturates: every caller is a
3
+ * color/channel packer, where wrapping would turn 1.004 into 0 (near-white to black) and
4
+ * negatives into arbitrary mid-range values.
2
5
  *
3
6
  * @param {number} v
4
- * @returns {number}
7
+ * @returns {number} integer in [0, 255]
5
8
  */
6
9
  export function float_to_uint8(v) {
7
- return Math.round(v * 255);
10
+ const whole = Math.round(v * 255);
11
+ // clamp to 0-255; masking with & 0xFF would wrap, not clamp
12
+ return whole < 0 ? 0 : (whole > 255 ? 255 : whole);
8
13
  }
@@ -1,10 +1,20 @@
1
1
  /**
2
+ * Tightens the relaxed planes of a frustum against the contents of a BVH: each relaxed
3
+ * plane is moved to the tightest position that still contains every leaf AABB surviving
4
+ * the fixed planes.
5
+ *
6
+ * Both input and output planes use the engine's inward `dot(normal, p) + offset >= 0`
7
+ * convention (see {@link v3_distance_above_plane}); fixed planes are copied through
8
+ * unchanged.
9
+ *
2
10
  * @param {number[]} result
3
11
  * @param {number} result_offset
4
12
  * @param {number} plane_mask if bit is set to 0, that plane is not allowed to move
5
13
  * @param {BVH} bvh
6
14
  * @param {number[]|ArrayLike<number>|Float32Array} frustum
7
- * @returns {boolean} true iff planes were updated, false otherwise. If false is returned - result is not written
15
+ * @returns {boolean} true iff every relaxed plane was tightened against geometry. False
16
+ * when the BVH is empty or when no leaf intersects the fixed planes — a relaxed plane
17
+ * would otherwise carry its infinite sentinel. If false is returned - result is not written
8
18
  */
9
19
  export function compute_tight_near_far_clipping_planes(result: number[], result_offset: number, plane_mask: number, bvh: BVH, frustum: number[] | ArrayLike<number> | Float32Array): boolean;
10
20
  //# sourceMappingURL=compute_tight_near_far_clipping_planes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compute_tight_near_far_clipping_planes.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,+DAPW,MAAM,EAAE,iBACR,MAAM,cACN,MAAM,qBAEN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,GACrC,OAAO,CA4MnB"}
1
+ {"version":3,"file":"compute_tight_near_far_clipping_planes.d.ts","sourceRoot":"","sources":["../../../../../../src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;GAiBG;AACH,+DATW,MAAM,EAAE,iBACR,MAAM,cACN,MAAM,qBAEN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,GACrC,OAAO,CA2NnB"}
@@ -11,12 +11,22 @@ const scratch_aabb = [];
11
11
  const scratch_frustum = new Float32Array(24);
12
12
 
13
13
  /**
14
+ * Tightens the relaxed planes of a frustum against the contents of a BVH: each relaxed
15
+ * plane is moved to the tightest position that still contains every leaf AABB surviving
16
+ * the fixed planes.
17
+ *
18
+ * Both input and output planes use the engine's inward `dot(normal, p) + offset >= 0`
19
+ * convention (see {@link v3_distance_above_plane}); fixed planes are copied through
20
+ * unchanged.
21
+ *
14
22
  * @param {number[]} result
15
23
  * @param {number} result_offset
16
24
  * @param {number} plane_mask if bit is set to 0, that plane is not allowed to move
17
25
  * @param {BVH} bvh
18
26
  * @param {number[]|ArrayLike<number>|Float32Array} frustum
19
- * @returns {boolean} true iff planes were updated, false otherwise. If false is returned - result is not written
27
+ * @returns {boolean} true iff every relaxed plane was tightened against geometry. False
28
+ * when the BVH is empty or when no leaf intersects the fixed planes — a relaxed plane
29
+ * would otherwise carry its infinite sentinel. If false is returned - result is not written
20
30
  */
21
31
  export function compute_tight_near_far_clipping_planes(
22
32
  result,
@@ -28,13 +38,17 @@ export function compute_tight_near_far_clipping_planes(
28
38
  assert.isNonNegativeInteger(result_offset, 'result_offset');
29
39
  assert.isNonNegativeInteger(plane_mask, 'plane_mask');
30
40
 
41
+ const relaxed_mask = plane_mask & 0b111111;
42
+
31
43
  // initialize result
32
44
  array_copy(frustum, 0, scratch_frustum, 0, 24);
33
45
 
34
- // set output planes to infinity so we can slowly bring them in
46
+ // Relaxed planes start infinitely tight ("no geometry seen yet") and are pushed out by
47
+ // leaves. In the dot+offset convention the tight containing offset is the running
48
+ // maximum of -dot(normal, nearest_corner), so the sentinel is -Infinity.
35
49
  for (let i = 0; i < 6; i++) {
36
- if (((plane_mask >> i) & 1) === 1) {
37
- scratch_frustum[i * 4 + 3] = Infinity;
50
+ if (((relaxed_mask >> i) & 1) === 1) {
51
+ scratch_frustum[i * 4 + 3] = -Infinity;
38
52
  }
39
53
  }
40
54
 
@@ -52,7 +66,8 @@ export function compute_tight_near_far_clipping_planes(
52
66
 
53
67
  stack[stack_top] = root;
54
68
 
55
- let result_cursor = result_offset;
69
+ // relaxed planes that have been tightened against at least one leaf
70
+ let updated_mask = 0;
56
71
 
57
72
  // 0 is the nearest point along the normal and 1 is the furthest
58
73
  let x0,
@@ -71,7 +86,6 @@ export function compute_tight_near_far_clipping_planes(
71
86
  */
72
87
  const node = stack[stack.pointer];
73
88
 
74
- // test node against the ray
75
89
  bvh.node_get_aabb(node, scratch_aabb);
76
90
 
77
91
  const _x0 = scratch_aabb[0];
@@ -122,15 +136,15 @@ export function compute_tight_near_far_clipping_planes(
122
136
  z1 = _z0;
123
137
  }
124
138
 
125
- if (((plane_mask >> plane_index) & 1) === 1) {
126
- // plane is not fixed, we're done here
127
-
139
+ if (((relaxed_mask >> plane_index) & 1) === 1) {
140
+ // relaxed plane: this node can push it out iff the node's nearest corner
141
+ // lies outside the current plane
128
142
  const distance_above_plane = v3_distance_above_plane(
129
143
  x0, y0, z0,
130
- plane_normal_x, plane_normal_y, plane_normal_z, 0
144
+ plane_normal_x, plane_normal_y, plane_normal_z, plane_offset
131
145
  );
132
146
 
133
- if (distance_above_plane < plane_offset) {
147
+ if (distance_above_plane < 0) {
134
148
  collision_mask |= (1 << plane_index);
135
149
  }
136
150
 
@@ -203,19 +217,28 @@ export function compute_tight_near_far_clipping_planes(
203
217
  z0 = _z1;
204
218
  }
205
219
 
206
- // move plane
207
- scratch_frustum[plane_address + 3] = v3_distance_above_plane(
220
+ // move the plane out to contain this leaf: offset = -dot(n, nearest
221
+ // corner) puts the corner exactly on the plane (dot + offset == 0).
222
+ // Only ever reached when the corner is outside the current plane
223
+ // (collision_mask gate), so the offset grows monotonically.
224
+ scratch_frustum[plane_address + 3] = -v3_distance_above_plane(
208
225
  x0, y0, z0,
209
226
  plane_normal_x, plane_normal_y, plane_normal_z, 0
210
227
  );
211
228
 
229
+ updated_mask |= (1 << i);
230
+
212
231
  }
213
232
  }
214
233
 
215
234
  }
216
235
  }
217
236
 
218
- // TODO check if results are still at infinity
237
+ if ((updated_mask & relaxed_mask) !== relaxed_mask) {
238
+ // some relaxed plane was never constrained by geometry (nothing intersects the
239
+ // fixed planes) — it still carries the -Infinity sentinel and must not leak out
240
+ return false;
241
+ }
219
242
 
220
243
  array_copy(scratch_frustum, 0, result, result_offset, 24);
221
244
 
@@ -1,9 +1,10 @@
1
1
  /**
2
- * This is not the standard gaussian.
3
- * It lacks the normalization factor, standard gaussian would be weighted by `1 / √(2π * variance)`
4
- * @param {number} sigma Standard deviation. Distance from mean. Represents the "width" of the Gaussian-like curve. Note: The parameter is named `sigma`, but its placement in the formula means it scales inversely to the usual effect of sigma.
5
- * @param {number} v Variance. Represents the "height" or "amplitude" of the curve, but at a distance from the mean. Larger variance values result in larger function values further away from the mean (0).
6
- * @returns {number} Ranges from 0 to 1 (exclusive of 0)
2
+ * Un-normalized gaussian: `exp(−distance² / (2·sigma²))`.
3
+ * This is not the standard gaussian it lacks the normalization factor;
4
+ * the standard gaussian would be weighted by `1 / √(2π·sigma²)`.
5
+ * @param {number} sigma Standard deviation. Controls the "width" of the bell curve: larger sigma wider curve, slower falloff with distance.
6
+ * @param {number} distance Distance from the mean (the point at which to evaluate the curve). At 0 the result is 1; it decays toward 0 as |distance| grows.
7
+ * @returns {number} Ranges from 0 to 1 (exclusive of 0, inclusive of 1 at distance 0)
7
8
  */
8
- export function gaussian(sigma: number, v: number): number;
9
+ export function gaussian(sigma: number, distance: number): number;
9
10
  //# sourceMappingURL=gaussian.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gaussian.d.ts","sourceRoot":"","sources":["../../../../src/core/math/gaussian.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,gCAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAOlB"}
1
+ {"version":3,"file":"gaussian.d.ts","sourceRoot":"","sources":["../../../../src/core/math/gaussian.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,gCAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAOlB"}
@@ -1,13 +1,14 @@
1
1
  /**
2
- * This is not the standard gaussian.
3
- * It lacks the normalization factor, standard gaussian would be weighted by `1 / √(2π * variance)`
4
- * @param {number} sigma Standard deviation. Distance from mean. Represents the "width" of the Gaussian-like curve. Note: The parameter is named `sigma`, but its placement in the formula means it scales inversely to the usual effect of sigma.
5
- * @param {number} v Variance. Represents the "height" or "amplitude" of the curve, but at a distance from the mean. Larger variance values result in larger function values further away from the mean (0).
6
- * @returns {number} Ranges from 0 to 1 (exclusive of 0)
2
+ * Un-normalized gaussian: `exp(−distance² / (2·sigma²))`.
3
+ * This is not the standard gaussian it lacks the normalization factor;
4
+ * the standard gaussian would be weighted by `1 / √(2π·sigma²)`.
5
+ * @param {number} sigma Standard deviation. Controls the "width" of the bell curve: larger sigma wider curve, slower falloff with distance.
6
+ * @param {number} distance Distance from the mean (the point at which to evaluate the curve). At 0 the result is 1; it decays toward 0 as |distance| grows.
7
+ * @returns {number} Ranges from 0 to 1 (exclusive of 0, inclusive of 1 at distance 0)
7
8
  */
8
- export function gaussian(sigma, v) {
9
- const v2 = v * v;
9
+ export function gaussian(sigma, distance) {
10
+ const d2 = distance * distance;
10
11
  const sigma2 = sigma * sigma;
11
12
 
12
- return Math.exp(- v2 / (2 * sigma2));
13
+ return Math.exp(- d2 / (2 * sigma2));
13
14
  }