@woosh/meep-engine 2.126.48 → 2.126.49

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/README.md CHANGED
@@ -13,7 +13,7 @@ To help get you started, various samples are provided under `/samples` folder. F
13
13
 
14
14
  ## Quality
15
15
 
16
- Meep is covered by 2,720 handwritten unit tests
16
+ Meep is covered by 2,753 handwritten unit tests
17
17
 
18
18
  The aim is to [ensure quality](https://about.codecov.io/blog/the-case-against-100-code-coverage/). As a result, the tests are written to cover complex code first and to exhaustively validate critical algorithms.
19
19
  Most of the test code is significantly larger than the code that is being tested.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Pure JavaScript game engine. Fully featured and production ready.",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.126.48",
8
+ "version": "2.126.49",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Carves out a slice of a frustum, given a normalized set of intervals [0,1] for each axis.
3
+ * Works with perspective and orthographic frustums.
4
+ * Input frustum is assumed to have planes in the following order [x0, x1, y0, y1, z0, z1]
5
+ * @param {number[]|Float32Array} output
6
+ * @param {number} output_offset
7
+ * @param {number[]|Float32Array} frustum
8
+ * @param {number} x0
9
+ * @param {number} y0
10
+ * @param {number} z0
11
+ * @param {number} x1
12
+ * @param {number} y1
13
+ * @param {number} z1
14
+ */
15
+ export function frustum_slice(output: number[] | Float32Array, output_offset: number, frustum: number[] | Float32Array, x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): void;
16
+ //# sourceMappingURL=frustum_slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frustum_slice.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/frustum/frustum_slice.js"],"names":[],"mappings":"AAoDA;;;;;;;;;;;;;GAaG;AACH,sCAVW,MAAM,EAAE,GAAC,YAAY,iBACrB,MAAM,WACN,MAAM,EAAE,GAAC,YAAY,MACrB,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QA6BhB"}
@@ -0,0 +1,94 @@
1
+ import { assert } from "../../../assert.js";
2
+ import { plane3_lerp } from "../plane/plane3_lerp.js";
3
+
4
+ /**
5
+ * Lerp between two planes of a frustum, opposing planes (x0,x1) or (y0,y1) or (z0,z1)
6
+ * @param {number[]} output
7
+ * @param {number} output_offset
8
+ * @param {number[]} input
9
+ * @param {number} plane_min_offset
10
+ * @param {number} plane_max_offset
11
+ * @param {number} section0
12
+ * @param {number} section1
13
+ */
14
+ function frustum_plane_pair_lerp(
15
+ output, output_offset,
16
+ input,
17
+ plane_min_offset,
18
+ plane_max_offset,
19
+ section0, section1
20
+ ) {
21
+
22
+ assert.isArrayLike(input, 'input');
23
+ assert.isNonNegativeInteger(plane_min_offset, 'plane_min_offset');
24
+ assert.isNonNegativeInteger(plane_max_offset, 'plane_max_offset');
25
+ assert.isNumber(section0, 'section0');
26
+ assert.isNumber(section1, 'section1');
27
+
28
+ const p0_nx = input[plane_min_offset];
29
+ const p0_ny = input[plane_min_offset + 1];
30
+ const p0_nz = input[plane_min_offset + 2];
31
+ const p0_c = input[plane_min_offset + 3];
32
+
33
+ const p1_nx = input[plane_max_offset];
34
+ const p1_ny = input[plane_max_offset + 1];
35
+ const p1_nz = input[plane_max_offset + 2];
36
+ const p1_c = input[plane_max_offset + 3];
37
+
38
+ plane3_lerp(
39
+ output, output_offset,
40
+ p0_nx, p0_ny, p0_nz, p0_c,
41
+ -p1_nx, -p1_ny, -p1_nz, -p1_c,
42
+ section0
43
+ );
44
+
45
+ plane3_lerp(
46
+ output, output_offset + 4,
47
+ -p0_nx, -p0_ny, -p0_nz, -p0_c,
48
+ p1_nx, p1_ny, p1_nz, p1_c,
49
+ section1
50
+ );
51
+ }
52
+
53
+ /**
54
+ * Carves out a slice of a frustum, given a normalized set of intervals [0,1] for each axis.
55
+ * Works with perspective and orthographic frustums.
56
+ * Input frustum is assumed to have planes in the following order [x0, x1, y0, y1, z0, z1]
57
+ * @param {number[]|Float32Array} output
58
+ * @param {number} output_offset
59
+ * @param {number[]|Float32Array} frustum
60
+ * @param {number} x0
61
+ * @param {number} y0
62
+ * @param {number} z0
63
+ * @param {number} x1
64
+ * @param {number} y1
65
+ * @param {number} z1
66
+ */
67
+ export function frustum_slice(
68
+ output, output_offset,
69
+ frustum,
70
+ x0, y0, z0,
71
+ x1, y1, z1,
72
+ ) {
73
+ // X planes
74
+ frustum_plane_pair_lerp(
75
+ output, output_offset,
76
+ frustum,
77
+ 0, 4, x0, x1,
78
+ );
79
+
80
+ // Y planes
81
+ frustum_plane_pair_lerp(
82
+ output, output_offset + 8,
83
+ frustum,
84
+ 0, 4, y0, y1,
85
+ );
86
+
87
+ // Z planes
88
+ frustum_plane_pair_lerp(
89
+ output, output_offset + 16,
90
+ frustum,
91
+ 0, 4, z0, z1,
92
+ );
93
+
94
+ }
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Multiplies two 4x4 matrices
2
+ * Multiplies two 4x4 matrices.
3
+ * `out = a * b`.
3
4
  *
4
5
  * @param {number[]|ArrayLike<number>|Float32Array} out the receiving matrix
5
6
  * @param {number[]|ArrayLike<number>|Float32Array} a the first operand
@@ -1 +1 @@
1
- {"version":3,"file":"m4_multiply.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/m4_multiply.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,iCAJW,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,KACvC,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,KACvC,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,QAwEjD"}
1
+ {"version":3,"file":"m4_multiply.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/m4_multiply.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,iCAJW,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,KACvC,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,KACvC,MAAM,EAAE,GAAC,SAAS,CAAC,MAAM,CAAC,GAAC,YAAY,QAwEjD"}
@@ -1,7 +1,8 @@
1
1
  import { assert } from "../../../assert.js";
2
2
 
3
3
  /**
4
- * Multiplies two 4x4 matrices
4
+ * Multiplies two 4x4 matrices.
5
+ * `out = a * b`.
5
6
  *
6
7
  * @param {number[]|ArrayLike<number>|Float32Array} out the receiving matrix
7
8
  * @param {number[]|ArrayLike<number>|Float32Array} a the first operand
@@ -1,6 +1,6 @@
1
1
  /**
2
- * TODO this produces increasingly incorrect when planes diverge
3
- * Interpolate between two planes in linear space
2
+ * Interpolate between two planes in linear space.
3
+ * Note: does not work for planes that are parallel with opposing normals.
4
4
  * @param {number[]} destination
5
5
  * @param {number} destination_offset
6
6
  * @param {number} a_normal_x
@@ -1 +1 @@
1
- {"version":3,"file":"plane3_lerp.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/plane/plane3_lerp.js"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;GAcG;AACH,yCAZW,MAAM,EAAE,sBACR,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,KACN,MAAM,QAuChB"}
1
+ {"version":3,"file":"plane3_lerp.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/plane/plane3_lerp.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,yCAZW,MAAM,EAAE,sBACR,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,KACN,MAAM,QAkBhB"}
@@ -1,15 +1,13 @@
1
1
  import { lerp } from "../../../math/lerp.js";
2
2
  import Vector3 from "../../Vector3.js";
3
- import { plane3_intersect_plane } from "./plane3_intersect_plane.js";
4
- import { v3_dot } from "../../vec3/v3_dot.js";
5
- import { v3_length } from "../../vec3/v3_length.js";
3
+ import { plane3_normalize } from "./plane3_normalize.js";
6
4
 
7
5
  const v0 = new Vector3();
8
6
  const v1 = new Vector3();
9
7
 
10
8
  /**
11
- * TODO this produces increasingly incorrect when planes diverge
12
- * Interpolate between two planes in linear space
9
+ * Interpolate between two planes in linear space.
10
+ * Note: does not work for planes that are parallel with opposing normals.
13
11
  * @param {number[]} destination
14
12
  * @param {number} destination_offset
15
13
  * @param {number} a_normal_x
@@ -28,35 +26,14 @@ export function plane3_lerp(
28
26
  b_normal_x, b_normal_y, b_normal_z, b_constant,
29
27
  t
30
28
  ) {
31
- // compute result normal
32
- let normal_x = lerp(a_normal_x, b_normal_x, t);
33
- let normal_y = lerp(a_normal_y, b_normal_y, t);
34
- let normal_z = lerp(a_normal_z, b_normal_z, t);
35
29
 
36
- // normalize the normal vector
37
- const normal_length = v3_length(normal_x, normal_y, normal_z);
38
- const normal_length_inv = 1 / normal_length;
30
+ const nx = lerp(a_normal_x, b_normal_x, t);
31
+ const ny = lerp(a_normal_y, b_normal_y, t);
32
+ const nz = lerp(a_normal_z, b_normal_z, t);
33
+ const c = lerp(a_constant, b_constant, t);
39
34
 
40
- normal_x *= normal_length_inv;
41
- normal_y *= normal_length_inv;
42
- normal_z *= normal_length_inv;
43
-
44
- // compute 2-plane intersection
45
- const intersection_exists = plane3_intersect_plane(v0, v1,
46
- a_normal_x, a_normal_y, a_normal_z, a_constant,
47
- b_normal_x, b_normal_y, b_normal_z, b_constant,
35
+ plane3_normalize(
36
+ destination, destination_offset,
37
+ nx, ny, nz, c
48
38
  );
49
-
50
- if (!intersection_exists) {
51
- // special case, planes are parallel
52
- // TODO implement handling
53
- }
54
-
55
- const r_constant = -v3_dot(v0.x, v0.y, v0.z, normal_x, normal_y, normal_z);
56
-
57
- // write result
58
- destination[destination_offset] = normal_x;
59
- destination[destination_offset + 1] = normal_y;
60
- destination[destination_offset + 2] = normal_z;
61
- destination[destination_offset + 3] = r_constant;
62
39
  }
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Normalizes plane representation
2
+ * Normalizes plane representation.
3
+ * Note plane normal must have a non-zero length.
3
4
  * @param {number[]} destination
4
5
  * @param {number} destination_offset
5
6
  * @param {number} x plane normal X
@@ -1 +1 @@
1
- {"version":3,"file":"plane3_normalize.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/plane/plane3_normalize.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,8CAPW,MAAM,EAAE,sBACR,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,QAgBhB"}
1
+ {"version":3,"file":"plane3_normalize.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/plane/plane3_normalize.js"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,8CAPW,MAAM,EAAE,sBACR,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,QAgBhB"}
@@ -1,7 +1,8 @@
1
1
  import { v3_length } from "../../vec3/v3_length.js";
2
2
 
3
3
  /**
4
- * Normalizes plane representation
4
+ * Normalizes plane representation.
5
+ * Note plane normal must have a non-zero length.
5
6
  * @param {number[]} destination
6
7
  * @param {number} destination_offset
7
8
  * @param {number} x plane normal X
@@ -1,17 +0,0 @@
1
- /**
2
- * TODO this produces increasingly incorrect when planes diverge
3
- * Interpolate between two planes in linear space
4
- * @param {number[]} destination
5
- * @param {number} destination_offset
6
- * @param {number} a_normal_x
7
- * @param {number} a_normal_y
8
- * @param {number} a_normal_z
9
- * @param {number} a_constant
10
- * @param {number} b_normal_x
11
- * @param {number} b_normal_y
12
- * @param {number} b_normal_z
13
- * @param {number} b_constant
14
- * @param {number} t
15
- */
16
- export function plane3_lerp_v0(destination: number[], destination_offset: number, a_normal_x: number, a_normal_y: number, a_normal_z: number, a_constant: number, b_normal_x: number, b_normal_y: number, b_normal_z: number, b_constant: number, t: number): void;
17
- //# sourceMappingURL=plane3_lerp_v0.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plane3_lerp_v0.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/plane/plane3_lerp_v0.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,4CAZW,MAAM,EAAE,sBACR,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,KACN,MAAM,QA8BhB"}
@@ -1,46 +0,0 @@
1
- import { lerp } from "../../../math/lerp.js";
2
-
3
- /**
4
- * TODO this produces increasingly incorrect when planes diverge
5
- * Interpolate between two planes in linear space
6
- * @param {number[]} destination
7
- * @param {number} destination_offset
8
- * @param {number} a_normal_x
9
- * @param {number} a_normal_y
10
- * @param {number} a_normal_z
11
- * @param {number} a_constant
12
- * @param {number} b_normal_x
13
- * @param {number} b_normal_y
14
- * @param {number} b_normal_z
15
- * @param {number} b_constant
16
- * @param {number} t
17
- */
18
- export function plane3_lerp_v0(
19
- destination, destination_offset,
20
- a_normal_x, a_normal_y, a_normal_z, a_constant,
21
- b_normal_x, b_normal_y, b_normal_z, b_constant,
22
- t
23
- ) {
24
-
25
- const n_x = lerp(a_normal_x, b_normal_x, t);
26
- const n_y = lerp(a_normal_y, b_normal_y, t);
27
- const n_z = lerp(a_normal_z, b_normal_z, t);
28
-
29
- const v_len_sqr = n_x * n_x + n_y * n_y + n_z * n_z;
30
-
31
- const v_len = Math.sqrt(v_len_sqr);
32
-
33
- const v_len_1 = 1 / v_len;
34
-
35
- const nn_x = n_x * v_len_1;
36
- const nn_y = n_y * v_len_1;
37
- const nn_z = n_z * v_len_1;
38
-
39
- const distance = lerp(a_constant, b_constant, t);
40
-
41
- // write result
42
- destination[destination_offset] = nn_x;
43
- destination[destination_offset + 1] = nn_y;
44
- destination[destination_offset + 2] = nn_z;
45
- destination[destination_offset + 3] = distance;
46
- }