@woosh/meep-engine 2.126.48 → 2.126.50
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 +1 -1
- package/package.json +1 -1
- package/src/core/geom/3d/frustum/frustum_slice.d.ts +16 -0
- package/src/core/geom/3d/frustum/frustum_slice.d.ts.map +1 -0
- package/src/core/geom/3d/frustum/frustum_slice.js +94 -0
- package/src/core/geom/3d/mat4/m4_multiply.d.ts +2 -1
- package/src/core/geom/3d/mat4/m4_multiply.d.ts.map +1 -1
- package/src/core/geom/3d/mat4/m4_multiply.js +2 -1
- package/src/core/geom/3d/plane/plane3_lerp.d.ts +3 -2
- package/src/core/geom/3d/plane/plane3_lerp.d.ts.map +1 -1
- package/src/core/geom/3d/plane/plane3_lerp.js +11 -36
- package/src/core/geom/3d/plane/plane3_normalize.d.ts +2 -1
- package/src/core/geom/3d/plane/plane3_normalize.d.ts.map +1 -1
- package/src/core/geom/3d/plane/plane3_normalize.js +2 -1
- package/src/core/geom/3d/plane/plane3_lerp_v0.d.ts +0 -17
- package/src/core/geom/3d/plane/plane3_lerp_v0.d.ts.map +0 -1
- package/src/core/geom/3d/plane/plane3_lerp_v0.js +0 -46
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,
|
|
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.
|
|
8
|
+
"version": "2.126.50",
|
|
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
|
+
8, 12, y0, y1,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Z planes
|
|
88
|
+
frustum_plane_pair_lerp(
|
|
89
|
+
output, output_offset + 16,
|
|
90
|
+
frustum,
|
|
91
|
+
16, 20, z0, z1,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"m4_multiply.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/m4_multiply.js"],"names":[],"mappings":"AAEA
|
|
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,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Interpolate between two planes in linear space.
|
|
3
|
+
*
|
|
4
|
+
* Note: It does not work for planes that are parallel with opposing normals. There is no valid solution, as the number of such planes would be infinite.
|
|
4
5
|
* @param {number[]} destination
|
|
5
6
|
* @param {number} destination_offset
|
|
6
7
|
* @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":"
|
|
1
|
+
{"version":3,"file":"plane3_lerp.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/plane/plane3_lerp.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;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,11 @@
|
|
|
1
1
|
import { lerp } from "../../../math/lerp.js";
|
|
2
|
-
import
|
|
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";
|
|
2
|
+
import { plane3_normalize } from "./plane3_normalize.js";
|
|
6
3
|
|
|
7
|
-
const v0 = new Vector3();
|
|
8
|
-
const v1 = new Vector3();
|
|
9
4
|
|
|
10
5
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
6
|
+
* Interpolate between two planes in linear space.
|
|
7
|
+
*
|
|
8
|
+
* Note: It does not work for planes that are parallel with opposing normals. There is no valid solution, as the number of such planes would be infinite.
|
|
13
9
|
* @param {number[]} destination
|
|
14
10
|
* @param {number} destination_offset
|
|
15
11
|
* @param {number} a_normal_x
|
|
@@ -28,35 +24,14 @@ export function plane3_lerp(
|
|
|
28
24
|
b_normal_x, b_normal_y, b_normal_z, b_constant,
|
|
29
25
|
t
|
|
30
26
|
) {
|
|
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
27
|
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
28
|
+
const nx = lerp(a_normal_x, b_normal_x, t);
|
|
29
|
+
const ny = lerp(a_normal_y, b_normal_y, t);
|
|
30
|
+
const nz = lerp(a_normal_z, b_normal_z, t);
|
|
31
|
+
const c = lerp(a_constant, b_constant, t);
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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,
|
|
33
|
+
plane3_normalize(
|
|
34
|
+
destination, destination_offset,
|
|
35
|
+
nx, ny, nz, c
|
|
48
36
|
);
|
|
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
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plane3_normalize.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/plane/plane3_normalize.js"],"names":[],"mappings":"AAEA
|
|
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
|
-
}
|