@woosh/meep-engine 2.126.34 → 2.126.36
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_compute_center.d.ts.map +1 -1
- package/src/core/geom/3d/frustum/frustum_compute_center.js +5 -0
- package/src/core/geom/3d/frustum/frustum_compute_corners.d.ts.map +1 -1
- package/src/core/geom/3d/frustum/frustum_compute_corners.js +11 -1
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.d.ts +1 -1
- package/src/core/geom/3d/mat4/MATRIX_4_IDENTITY.js +1 -1
- package/src/core/geom/3d/mat4/eulerAnglesFromMatrix.d.ts +4 -4
- package/src/core/geom/3d/mat4/eulerAnglesFromMatrix.d.ts.map +1 -1
- package/src/core/geom/3d/mat4/eulerAnglesFromMatrix.js +27 -27
- package/src/core/geom/3d/mat4/m4_inverse_rotation_translation.d.ts +9 -0
- package/src/core/geom/3d/mat4/m4_inverse_rotation_translation.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_inverse_rotation_translation.js +40 -0
- package/src/core/geom/3d/mat4/m4_multiply.d.ts +0 -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/mat4/m4_rotation_translation.d.ts +9 -0
- package/src/core/geom/3d/mat4/m4_rotation_translation.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_rotation_translation.js +32 -0
- package/src/core/geom/Quaternion.d.ts +22 -13
- package/src/core/geom/Quaternion.d.ts.map +1 -1
- package/src/core/geom/Quaternion.js +54 -24
- package/src/core/geom/Vector1.d.ts +7 -1
- package/src/core/geom/Vector1.d.ts.map +1 -1
- package/src/core/geom/Vector1.js +6 -0
- package/src/core/geom/Vector2.d.ts +11 -1
- package/src/core/geom/Vector2.d.ts.map +1 -1
- package/src/core/geom/Vector2.js +10 -0
- package/src/core/geom/Vector3.d.ts +12 -2
- package/src/core/geom/Vector3.d.ts.map +1 -1
- package/src/core/geom/Vector3.js +11 -1
- package/src/core/geom/Vector4.d.ts +20 -2
- package/src/core/geom/Vector4.d.ts.map +1 -1
- package/src/core/geom/Vector4.js +26 -6
- package/src/core/geom/mat3/m3_make_rotation.d.ts +9 -0
- package/src/core/geom/mat3/m3_make_rotation.d.ts.map +1 -0
- package/src/core/geom/mat3/m3_make_rotation.js +31 -0
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,720 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.36",
|
|
9
9
|
"main": "build/meep.module.js",
|
|
10
10
|
"module": "build/meep.module.js",
|
|
11
11
|
"exports": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frustum_compute_center.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/frustum/frustum_compute_center.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"frustum_compute_center.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/frustum/frustum_compute_center.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,+CALW,MAAM,EAAE,iBACR,MAAM,WACN,MAAM,EAAE,kBACR,MAAM,QA8BhB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
1
2
|
import { frustum_compute_corners } from "./frustum_compute_corners.js";
|
|
2
3
|
|
|
3
4
|
const scratch_corners = new Float32Array(24);
|
|
@@ -15,6 +16,10 @@ export function frustum_compute_center(
|
|
|
15
16
|
frustum,
|
|
16
17
|
frustum_offset
|
|
17
18
|
) {
|
|
19
|
+
assert.defined(output,'output');
|
|
20
|
+
assert.isNonNegativeInteger(output_offset,'output_offset');
|
|
21
|
+
assert.defined(frustum,'frustum');
|
|
22
|
+
assert.isNonNegativeInteger(frustum_offset,'frustum_offset');
|
|
18
23
|
|
|
19
24
|
frustum_compute_corners(scratch_corners, 0, frustum, frustum_offset);
|
|
20
25
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frustum_compute_corners.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/frustum/frustum_compute_corners.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"frustum_compute_corners.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/frustum/frustum_compute_corners.js"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AACH,gDALW,MAAM,EAAE,GAAC,YAAY,iBACrB,MAAM,WACN,MAAM,EAAE,GAAC,YAAY,kBACrB,MAAM,QAgFhB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assert } from "../../../assert.js";
|
|
1
2
|
import { plane3_compute_convex_3_plane_intersection } from "../plane/plane3_compute_convex_3_plane_intersection.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -9,7 +10,16 @@ import { plane3_compute_convex_3_plane_intersection } from "../plane/plane3_comp
|
|
|
9
10
|
* @param {number[]|Float32Array} frustum defined as [plane_normal_x, plane_normal_y, plane_normal_z, plane_offset], planes should be in the following order [x0, x1, y0, y1, z0, z1]
|
|
10
11
|
* @param {number} frustum_offset where to start reading from
|
|
11
12
|
*/
|
|
12
|
-
export function frustum_compute_corners(
|
|
13
|
+
export function frustum_compute_corners(
|
|
14
|
+
output,
|
|
15
|
+
output_offset,
|
|
16
|
+
frustum,
|
|
17
|
+
frustum_offset
|
|
18
|
+
) {
|
|
19
|
+
assert.defined(output,'output');
|
|
20
|
+
assert.isNonNegativeInteger(output_offset,'output_offset');
|
|
21
|
+
assert.defined(frustum,'frustum');
|
|
22
|
+
assert.isNonNegativeInteger(frustum_offset,'frustum_offset');
|
|
13
23
|
|
|
14
24
|
const f = frustum;
|
|
15
25
|
const o = frustum_offset;
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
* NOTE: ported from Eigen C++ library
|
|
19
19
|
* @see https://gitlab.com/libeigen/eigen/-/blob/master/Eigen/src/Geometry/EulerAngles.h
|
|
20
20
|
* @see https://stackoverflow.com/questions/11514063/extract-yaw-pitch-and-roll-from-a-rotationmatrix
|
|
21
|
-
* @param {number[]}
|
|
22
|
-
* @param {number[]|Float32Array|mat4} m4
|
|
23
|
-
* @param {number} a0 axis index
|
|
21
|
+
* @param {number[]} output
|
|
22
|
+
* @param {number[]|Float32Array|mat4} m4 source matrix to extract rotation from
|
|
23
|
+
* @param {number} a0 axis index (0 = X, 1 = Y, 2 = Z)
|
|
24
24
|
* @param {number} a1 axis index
|
|
25
25
|
* @param {number} a2 axis index
|
|
26
26
|
*/
|
|
27
|
-
export function eulerAnglesFromMatrix(
|
|
27
|
+
export function eulerAnglesFromMatrix(output: number[], m4: number[] | Float32Array | mat4, a0: number, a1: number, a2: number): void;
|
|
28
28
|
//# sourceMappingURL=eulerAnglesFromMatrix.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eulerAnglesFromMatrix.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/eulerAnglesFromMatrix.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,
|
|
1
|
+
{"version":3,"file":"eulerAnglesFromMatrix.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/eulerAnglesFromMatrix.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,8CANW,MAAM,EAAE,MACR,MAAM,EAAE,GAAC,YAAY,GAAC,IAAI,MAC1B,MAAM,MACN,MAAM,MACN,MAAM,QA2EhB"}
|
|
@@ -36,14 +36,14 @@ const atan2 = Math.atan2;
|
|
|
36
36
|
* NOTE: ported from Eigen C++ library
|
|
37
37
|
* @see https://gitlab.com/libeigen/eigen/-/blob/master/Eigen/src/Geometry/EulerAngles.h
|
|
38
38
|
* @see https://stackoverflow.com/questions/11514063/extract-yaw-pitch-and-roll-from-a-rotationmatrix
|
|
39
|
-
* @param {number[]}
|
|
40
|
-
* @param {number[]|Float32Array|mat4} m4
|
|
41
|
-
* @param {number} a0 axis index
|
|
39
|
+
* @param {number[]} output
|
|
40
|
+
* @param {number[]|Float32Array|mat4} m4 source matrix to extract rotation from
|
|
41
|
+
* @param {number} a0 axis index (0 = X, 1 = Y, 2 = Z)
|
|
42
42
|
* @param {number} a1 axis index
|
|
43
43
|
* @param {number} a2 axis index
|
|
44
44
|
*/
|
|
45
45
|
export function eulerAnglesFromMatrix(
|
|
46
|
-
|
|
46
|
+
output, m4,
|
|
47
47
|
a0, a1, a2
|
|
48
48
|
) {
|
|
49
49
|
|
|
@@ -54,19 +54,19 @@ export function eulerAnglesFromMatrix(
|
|
|
54
54
|
const k = (a0 + 2 - odd) % 3;
|
|
55
55
|
|
|
56
56
|
if (a0 === a2) {
|
|
57
|
-
|
|
57
|
+
output[0] = atan2(coeff(m4, j, i), coeff(m4, k, i));
|
|
58
58
|
|
|
59
|
-
if ((odd &&
|
|
60
|
-
if (
|
|
61
|
-
|
|
59
|
+
if ((odd && output[0] < 0) || ((~odd) && output[0] > 0)) {
|
|
60
|
+
if (output[0] > 0) {
|
|
61
|
+
output[0] -= Math.PI;
|
|
62
62
|
} else {
|
|
63
|
-
|
|
63
|
+
output[0] += Math.PI;
|
|
64
64
|
}
|
|
65
65
|
const s2 = v2_length(coeff(m4, j, i), coeff(m4, k, i));
|
|
66
|
-
|
|
66
|
+
output[1] = -atan2(s2, coeff(m4, i, i));
|
|
67
67
|
} else {
|
|
68
68
|
const s2 = v2_length(coeff(m4, j, i), coeff(m4, k, i));
|
|
69
|
-
|
|
69
|
+
output[1] = atan2(s2, coeff(m4, i, i));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// With a=(0,1,0), we have i=0; j=1; k=2, and after computing the first two angles,
|
|
@@ -79,40 +79,40 @@ export function eulerAnglesFromMatrix(
|
|
|
79
79
|
//
|
|
80
80
|
// Thus: m11.c1 - m21.s1 = c3 & m12.c1 - m22.s1 = s3
|
|
81
81
|
|
|
82
|
-
const s1 = sin(
|
|
83
|
-
const c1 = cos(
|
|
82
|
+
const s1 = sin(output[0]);
|
|
83
|
+
const c1 = cos(output[0]);
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
output[2] = atan2(c1 * coeff(m4, j, k) - s1 * coeff(m4, k, k), c1 * coeff(m4, j, j) - s1 * coeff(m4, k, j));
|
|
86
86
|
|
|
87
87
|
} else {
|
|
88
88
|
|
|
89
|
-
|
|
89
|
+
output[0] = atan2(coeff(m4, j, k), coeff(m4, k, k));
|
|
90
90
|
|
|
91
91
|
const c2 = v2_length(coeff(m4, i, i), coeff(m4, i, j));
|
|
92
92
|
|
|
93
|
-
if ((odd &&
|
|
94
|
-
if (
|
|
95
|
-
|
|
93
|
+
if ((odd && output[0] < 0) || ((~odd) && output[0] > 0)) {
|
|
94
|
+
if (output[0] > 0) {
|
|
95
|
+
output[0] -= Math.PI;
|
|
96
96
|
} else {
|
|
97
|
-
|
|
97
|
+
output[0] += Math.PI;
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
output[1] = atan2(-coeff(m4, i, k), -c2);
|
|
100
100
|
} else {
|
|
101
|
-
|
|
101
|
+
output[1] = atan2(-coeff(m4, i, k), c2);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
const s1 = sin(
|
|
105
|
-
const c1 = cos(
|
|
104
|
+
const s1 = sin(output[0]);
|
|
105
|
+
const c1 = cos(output[0]);
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
output[2] = atan2(s1 * coeff(m4, k, i) - c1 * coeff(m4, j, i), c1 * coeff(m4, j, j) - s1 * coeff(m4, k, j));
|
|
108
108
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
if (odd === 0) {
|
|
112
112
|
// invert result
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
output[0] = -output[0];
|
|
114
|
+
output[1] = -output[1];
|
|
115
|
+
output[2] = -output[2];
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compose an inverse 4x4 transformation matrix from 3x3 rotation matrix and a translation vector
|
|
3
|
+
* @param {number[]} output 4x4 matrix
|
|
4
|
+
* @param {number[]} rotation_matrix 3x3 mat
|
|
5
|
+
* @param {number[]} translation 3d vector
|
|
6
|
+
* @see m4_rotation_translation
|
|
7
|
+
*/
|
|
8
|
+
export function m4_inverse_rotation_translation(output: number[], rotation_matrix: number[], translation: number[]): void;
|
|
9
|
+
//# sourceMappingURL=m4_inverse_rotation_translation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"m4_inverse_rotation_translation.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/m4_inverse_rotation_translation.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wDALW,MAAM,EAAE,mBACR,MAAM,EAAE,eACR,MAAM,EAAE,QAiClB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { v3_dot } from "../../vec3/v3_dot.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compose an inverse 4x4 transformation matrix from 3x3 rotation matrix and a translation vector
|
|
5
|
+
* @param {number[]} output 4x4 matrix
|
|
6
|
+
* @param {number[]} rotation_matrix 3x3 mat
|
|
7
|
+
* @param {number[]} translation 3d vector
|
|
8
|
+
* @see m4_rotation_translation
|
|
9
|
+
*/
|
|
10
|
+
export function m4_inverse_rotation_translation(
|
|
11
|
+
output,
|
|
12
|
+
rotation_matrix,
|
|
13
|
+
translation
|
|
14
|
+
) {
|
|
15
|
+
|
|
16
|
+
const r = rotation_matrix;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
output[0] = r[0];
|
|
20
|
+
output[1] = r[3];
|
|
21
|
+
output[2] = r[6];
|
|
22
|
+
output[3] = 0;
|
|
23
|
+
|
|
24
|
+
output[4] = r[1];
|
|
25
|
+
output[5] = r[4];
|
|
26
|
+
output[6] = r[7];
|
|
27
|
+
output[7] = 0;
|
|
28
|
+
|
|
29
|
+
output[8] = r[2];
|
|
30
|
+
output[9] = r[5];
|
|
31
|
+
output[10] = r[8];
|
|
32
|
+
output[11] = 0;
|
|
33
|
+
|
|
34
|
+
const t = translation;
|
|
35
|
+
|
|
36
|
+
output[12] = -v3_dot(t[0], t[1], t[2], r[0], r[1], r[2]);
|
|
37
|
+
output[13] = -v3_dot(t[0], t[1], t[2], r[3], r[4], r[5]);
|
|
38
|
+
output[14] = -v3_dot(t[0], t[1], t[2], r[6], r[7], r[8]);
|
|
39
|
+
output[15] = 1;
|
|
40
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"m4_multiply.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/m4_multiply.js"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"m4_multiply.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/m4_multiply.js"],"names":[],"mappings":"AAAA;;;;;;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,QA8DjD"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Multiplies two 4x4 matrices
|
|
3
|
-
* Adapted from gl-matrix
|
|
4
3
|
*
|
|
5
4
|
* @param {number[]|ArrayLike<number>|Float32Array} out the receiving matrix
|
|
6
5
|
* @param {number[]|ArrayLike<number>|Float32Array} a the first operand
|
|
7
6
|
* @param {number[]|ArrayLike<number>|Float32Array} b the second operand
|
|
8
7
|
*/
|
|
9
8
|
export function m4_multiply(out, a, b) {
|
|
9
|
+
// Adapted from gl-matrix
|
|
10
|
+
|
|
10
11
|
const a00 = a[0],
|
|
11
12
|
a01 = a[1],
|
|
12
13
|
a02 = a[2],
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compose a 4x4 transformation matrix from 3x3 rotation matrix and a translation vector
|
|
3
|
+
* @param {number[]} output 4x4 matrix
|
|
4
|
+
* @param {number[]} rotation_matrix 3x3 mat
|
|
5
|
+
* @param {number[]} translation 3d vector
|
|
6
|
+
* @see m4_inverse_rotation_translation
|
|
7
|
+
*/
|
|
8
|
+
export function m4_rotation_translation(output: number[], rotation_matrix: number[], translation: number[]): void;
|
|
9
|
+
//# sourceMappingURL=m4_rotation_translation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"m4_rotation_translation.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/mat4/m4_rotation_translation.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,gDALW,MAAM,EAAE,mBACR,MAAM,EAAE,eACR,MAAM,EAAE,QA2BlB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compose a 4x4 transformation matrix from 3x3 rotation matrix and a translation vector
|
|
3
|
+
* @param {number[]} output 4x4 matrix
|
|
4
|
+
* @param {number[]} rotation_matrix 3x3 mat
|
|
5
|
+
* @param {number[]} translation 3d vector
|
|
6
|
+
* @see m4_inverse_rotation_translation
|
|
7
|
+
*/
|
|
8
|
+
export function m4_rotation_translation(output, rotation_matrix, translation) {
|
|
9
|
+
const r = rotation_matrix;
|
|
10
|
+
|
|
11
|
+
output[0] = r[0];
|
|
12
|
+
output[1] = r[1];
|
|
13
|
+
output[2] = r[2];
|
|
14
|
+
output[3] = 0;
|
|
15
|
+
|
|
16
|
+
output[4] = r[3];
|
|
17
|
+
output[5] = r[4];
|
|
18
|
+
output[6] = r[5];
|
|
19
|
+
output[7] = 0;
|
|
20
|
+
|
|
21
|
+
output[8] = r[6];
|
|
22
|
+
output[9] = r[7];
|
|
23
|
+
output[10] = r[8];
|
|
24
|
+
output[11] = 0;
|
|
25
|
+
|
|
26
|
+
const t = translation;
|
|
27
|
+
|
|
28
|
+
output[12] = t[0];
|
|
29
|
+
output[13] = t[1];
|
|
30
|
+
output[14] = t[2];
|
|
31
|
+
output[15] = 1;
|
|
32
|
+
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Implementation of a quaternion.
|
|
3
|
+
* Represents rotation in 3d space
|
|
4
|
+
*
|
|
5
|
+
* Iterating through a Quaternion instance will yield its components `(x, y, z, w)` in the corresponding order.
|
|
6
|
+
*
|
|
3
7
|
* @see https://en.wikipedia.org/wiki/Quaternion
|
|
8
|
+
* @implements Iterable<number>
|
|
4
9
|
*
|
|
5
10
|
* @author Alex Goldring
|
|
6
11
|
* @copyright Company Named Limited (c) 2025
|
|
7
12
|
*/
|
|
8
|
-
export class Quaternion {
|
|
13
|
+
export class Quaternion implements Iterable<number> {
|
|
9
14
|
/**
|
|
10
15
|
*
|
|
11
16
|
* @param {Vector3} axis
|
|
@@ -154,24 +159,27 @@ export class Quaternion {
|
|
|
154
159
|
*/
|
|
155
160
|
angleTo(other: Quaternion): number;
|
|
156
161
|
/**
|
|
157
|
-
*
|
|
162
|
+
* Set quaternion from axis + angle definition
|
|
158
163
|
* @param {Vector3} axis
|
|
159
164
|
* @param {number} angle
|
|
160
165
|
*/
|
|
161
166
|
fromAxisAngle(axis: Vector3, angle: number): void;
|
|
162
167
|
/**
|
|
163
168
|
*
|
|
164
|
-
* @param {number}
|
|
165
|
-
* @param {number}
|
|
166
|
-
* @param {number}
|
|
169
|
+
* @param {number} axis_x
|
|
170
|
+
* @param {number} axis_y
|
|
171
|
+
* @param {number} axis_z
|
|
167
172
|
* @param {number} angle
|
|
168
173
|
*/
|
|
169
|
-
_fromAxisAngle(
|
|
174
|
+
_fromAxisAngle(axis_x: number, axis_y: number, axis_z: number, angle: number): void;
|
|
170
175
|
/**
|
|
171
|
-
*
|
|
176
|
+
* Given a direction axis, compute rotation quaternions from current rotation to that axis as swing and twist. Swing moves to a given orientation while without "twisting",
|
|
177
|
+
* `twist` just the twist around the given axis, no change in orientation.
|
|
172
178
|
* @param {Vector3} axis
|
|
173
|
-
* @param {Quaternion} swing
|
|
174
|
-
* @param {Quaternion} twist
|
|
179
|
+
* @param {Quaternion} swing Swing quaternion will be written here
|
|
180
|
+
* @param {Quaternion} twist Twist quaternion will be written here
|
|
181
|
+
* @returns {void}
|
|
182
|
+
* @see slerp
|
|
175
183
|
*/
|
|
176
184
|
computeSwingAndTwist(axis: Vector3, swing: Quaternion, twist: Quaternion): void;
|
|
177
185
|
/**
|
|
@@ -251,7 +259,7 @@ export class Quaternion {
|
|
|
251
259
|
* @param {number} x
|
|
252
260
|
* @param {number} y
|
|
253
261
|
* @param {number} z
|
|
254
|
-
* @param {String} [order] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
|
|
262
|
+
* @param {String} [order='XYZ'] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
|
|
255
263
|
* @returns {Quaternion}
|
|
256
264
|
*/
|
|
257
265
|
__setFromEuler(x: number, y: number, z: number, order?: string): Quaternion;
|
|
@@ -477,9 +485,10 @@ export class Quaternion {
|
|
|
477
485
|
*/
|
|
478
486
|
writeToArray(array?: number[], offset?: number): number[];
|
|
479
487
|
/**
|
|
480
|
-
*
|
|
488
|
+
* Strict equality check
|
|
481
489
|
* @param {Quaternion} other
|
|
482
490
|
* @returns {boolean}
|
|
491
|
+
* @see roughlyEquals
|
|
483
492
|
*/
|
|
484
493
|
equals(other: Quaternion): boolean;
|
|
485
494
|
/**
|
|
@@ -500,7 +509,7 @@ export class Quaternion {
|
|
|
500
509
|
* @param {number} y
|
|
501
510
|
* @param {number} z
|
|
502
511
|
* @param {number} w
|
|
503
|
-
* @param {number} [tolerance]
|
|
512
|
+
* @param {number} [tolerance] acceptable difference value per coordinate
|
|
504
513
|
* @return {boolean}
|
|
505
514
|
*/
|
|
506
515
|
_roughlyEquals(x: number, y: number, z: number, w: number, tolerance?: number): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Quaternion.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Quaternion.js"],"names":[],"mappings":"AAoBA;;;;;;;;;;;GAWG;AACH,mCALe,QAAQ,CAAC,MAAM;IA4R1B;;;;;OAKG;IACH,2BAJW,OAAO,SACP,MAAM,GACJ,UAAU,CAQtB;IAqpCD;;;;OAIG;IACH,kCAFa,UAAU,CAQtB;IAED;;;;;;;OAOG;IACH,0BALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,UAAU,CAQtB;IAED;;;;;;OAMG;IACH,6BALW,UAAU,QACV,UAAU,MACV,UAAU,aACV,MAAM,QAuBhB;IAh/CD;;;;;;;OAOG;IACH,gBANW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,EAsChB;IA7BG;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;IACV;;;OAGG;IACH,GAFU,MAAM,CAEN;I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,cACN,MAAM,GACL,OAAO,CASlB;IAED;;;;OAIG;IACH,gBAHW,MAAW,MAAM,GAChB,UAAU,CAuBrB;IAED,mBAEC;IA8DL,mBAjLe,MAAM,EAAE,WACR,MAAM,gBAgLS;IAC9B,kBAnKe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CAiKG;IAC5B,kBApKe,MAAM,EAAE,WACR,MAAM,KACJ,MAAM,EAAE,CAkKG;IAC5B,qBAxyBe,MAAM,KACN,MAAM,KACN,MAAM,gBAsyBe;IAQpC;;;;OAIG;IACH,uBAFU,OAAO,CAEgB;IAp5C7B;;;OAGG;IACH,qBAFa,SAAS,CAAC,MAAM,CAAC,CAS7B;CAu3CJ;;kBASS,UAAU;kBAaV,MAAM;;;mBAviDG,4BAA4B;oBAU3B,cAAc"}
|
|
@@ -5,6 +5,7 @@ import { clamp01 } from "../math/clamp01.js";
|
|
|
5
5
|
import { EPSILON } from "../math/EPSILON.js";
|
|
6
6
|
import { epsilonEquals } from "../math/epsilonEquals.js";
|
|
7
7
|
import { lerp } from "../math/lerp.js";
|
|
8
|
+
import { PI2 } from "../math/PI2.js";
|
|
8
9
|
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
9
10
|
import { v3_dot } from "./vec3/v3_dot.js";
|
|
10
11
|
import { v4_length } from "./vec4/v4_length.js";
|
|
@@ -18,8 +19,13 @@ const sin = Math.sin;
|
|
|
18
19
|
const cos = Math.cos;
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
+
* Implementation of a quaternion.
|
|
23
|
+
* Represents rotation in 3d space
|
|
24
|
+
*
|
|
25
|
+
* Iterating through a Quaternion instance will yield its components `(x, y, z, w)` in the corresponding order.
|
|
26
|
+
*
|
|
22
27
|
* @see https://en.wikipedia.org/wiki/Quaternion
|
|
28
|
+
* @implements Iterable<number>
|
|
23
29
|
*
|
|
24
30
|
* @author Alex Goldring
|
|
25
31
|
* @copyright Company Named Limited (c) 2025
|
|
@@ -207,7 +213,7 @@ export class Quaternion {
|
|
|
207
213
|
const m12 = scratch_v3_a.y;
|
|
208
214
|
const m22 = scratch_v3_a.z;
|
|
209
215
|
|
|
210
|
-
|
|
216
|
+
return this.__setFromRotationMatrix(
|
|
211
217
|
m00, m01, m02,
|
|
212
218
|
m10, m11, m12,
|
|
213
219
|
m20, m21, m22
|
|
@@ -318,7 +324,7 @@ export class Quaternion {
|
|
|
318
324
|
}
|
|
319
325
|
|
|
320
326
|
/**
|
|
321
|
-
*
|
|
327
|
+
* Set quaternion from axis + angle definition
|
|
322
328
|
* @param {Vector3} axis
|
|
323
329
|
* @param {number} angle
|
|
324
330
|
*/
|
|
@@ -330,25 +336,30 @@ export class Quaternion {
|
|
|
330
336
|
|
|
331
337
|
/**
|
|
332
338
|
*
|
|
333
|
-
* @param {number}
|
|
334
|
-
* @param {number}
|
|
335
|
-
* @param {number}
|
|
339
|
+
* @param {number} axis_x
|
|
340
|
+
* @param {number} axis_y
|
|
341
|
+
* @param {number} axis_z
|
|
336
342
|
* @param {number} angle
|
|
337
343
|
*/
|
|
338
|
-
_fromAxisAngle(
|
|
339
|
-
assert.isNumber(
|
|
340
|
-
assert.isNumber(
|
|
341
|
-
assert.isNumber(
|
|
344
|
+
_fromAxisAngle(axis_x, axis_y, axis_z, angle) {
|
|
345
|
+
assert.isNumber(axis_x, 'axis_x');
|
|
346
|
+
assert.isNumber(axis_y, 'axis_y');
|
|
347
|
+
assert.isNumber(axis_z, 'axis_z');
|
|
342
348
|
assert.isNumber(angle, 'angle');
|
|
343
349
|
|
|
350
|
+
assert.notNaN(axis_x, 'axis_x');
|
|
351
|
+
assert.notNaN(axis_y, 'axis_y');
|
|
352
|
+
assert.notNaN(axis_z, 'axis_z');
|
|
353
|
+
assert.notNaN(angle, 'angle');
|
|
354
|
+
|
|
344
355
|
const halfAngle = angle * 0.5;
|
|
345
356
|
|
|
346
357
|
const sinA2 = sin(halfAngle);
|
|
347
358
|
const cosA2 = cos(halfAngle);
|
|
348
359
|
|
|
349
|
-
const qx =
|
|
350
|
-
const qy =
|
|
351
|
-
const qz =
|
|
360
|
+
const qx = axis_x * sinA2;
|
|
361
|
+
const qy = axis_y * sinA2;
|
|
362
|
+
const qz = axis_z * sinA2;
|
|
352
363
|
const qw = cosA2;
|
|
353
364
|
|
|
354
365
|
//normalize
|
|
@@ -365,12 +376,21 @@ export class Quaternion {
|
|
|
365
376
|
}
|
|
366
377
|
|
|
367
378
|
/**
|
|
368
|
-
*
|
|
379
|
+
* Given a direction axis, compute rotation quaternions from current rotation to that axis as swing and twist. Swing moves to a given orientation while without "twisting",
|
|
380
|
+
* `twist` just the twist around the given axis, no change in orientation.
|
|
369
381
|
* @param {Vector3} axis
|
|
370
|
-
* @param {Quaternion} swing
|
|
371
|
-
* @param {Quaternion} twist
|
|
382
|
+
* @param {Quaternion} swing Swing quaternion will be written here
|
|
383
|
+
* @param {Quaternion} twist Twist quaternion will be written here
|
|
384
|
+
* @returns {void}
|
|
385
|
+
* @see slerp
|
|
372
386
|
*/
|
|
373
387
|
computeSwingAndTwist(axis, swing, twist) {
|
|
388
|
+
assert.defined(axis, 'axis');
|
|
389
|
+
assert.defined(swing, 'swing');
|
|
390
|
+
assert.defined(twist, 'twist');
|
|
391
|
+
|
|
392
|
+
// see https://stackoverflow.com/questions/3684269/component-of-a-quaternion-rotation-around-an-axis
|
|
393
|
+
|
|
374
394
|
const x = this.x;
|
|
375
395
|
const y = this.y;
|
|
376
396
|
const z = this.z;
|
|
@@ -388,16 +408,19 @@ export class Quaternion {
|
|
|
388
408
|
const pz = axis.z * m;
|
|
389
409
|
|
|
390
410
|
if (d < 0) {
|
|
411
|
+
|
|
391
412
|
// axis points in the opposite direction from calculated twist, invert all components
|
|
392
413
|
twist.set(-px, -py, -pz, -w);
|
|
414
|
+
|
|
393
415
|
} else {
|
|
416
|
+
|
|
394
417
|
twist.set(px, py, pz, w);
|
|
395
418
|
|
|
396
419
|
}
|
|
397
420
|
|
|
398
421
|
twist.normalize();
|
|
399
422
|
|
|
400
|
-
// rotation * twist.conjugated()
|
|
423
|
+
// rotation * twist.conjugated(), basically undo the twist
|
|
401
424
|
swing._multiplyQuaternions(x, y, z, w, -twist.x, -twist.y, -twist.z, twist.w);
|
|
402
425
|
}
|
|
403
426
|
|
|
@@ -414,7 +437,7 @@ export class Quaternion {
|
|
|
414
437
|
|
|
415
438
|
this.computeSwingAndTwist(axis, swing, twist);
|
|
416
439
|
|
|
417
|
-
//
|
|
440
|
+
// Extract the twist angle from quaternion, see {@link #toAxisAngle}
|
|
418
441
|
return Math.acos(twist.w) * 2;
|
|
419
442
|
}
|
|
420
443
|
|
|
@@ -583,7 +606,7 @@ export class Quaternion {
|
|
|
583
606
|
* @param {number} x
|
|
584
607
|
* @param {number} y
|
|
585
608
|
* @param {number} z
|
|
586
|
-
* @param {String} [order] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
|
|
609
|
+
* @param {String} [order='XYZ'] a combination of capital letters X,Y,Z. Examples: XYZ, YXZ
|
|
587
610
|
* @returns {Quaternion}
|
|
588
611
|
*/
|
|
589
612
|
__setFromEuler(
|
|
@@ -1163,6 +1186,7 @@ export class Quaternion {
|
|
|
1163
1186
|
|
|
1164
1187
|
// calculate coefficients
|
|
1165
1188
|
if ((1.0 - cos_angle) > EPSILON) {
|
|
1189
|
+
|
|
1166
1190
|
// standard case (slerp)
|
|
1167
1191
|
const angle = Math.acos(cos_angle);
|
|
1168
1192
|
|
|
@@ -1172,10 +1196,12 @@ export class Quaternion {
|
|
|
1172
1196
|
scale1 = sin(t * angle) * recip_sin_angle;
|
|
1173
1197
|
|
|
1174
1198
|
} else {
|
|
1199
|
+
|
|
1175
1200
|
// "from" and "to" quaternions are very close
|
|
1176
1201
|
// ... so we can do a linear interpolation
|
|
1177
1202
|
scale0 = 1.0 - t;
|
|
1178
1203
|
scale1 = t;
|
|
1204
|
+
|
|
1179
1205
|
}
|
|
1180
1206
|
|
|
1181
1207
|
// calculate final values
|
|
@@ -1380,9 +1406,10 @@ export class Quaternion {
|
|
|
1380
1406
|
}
|
|
1381
1407
|
|
|
1382
1408
|
/**
|
|
1383
|
-
*
|
|
1409
|
+
* Strict equality check
|
|
1384
1410
|
* @param {Quaternion} other
|
|
1385
1411
|
* @returns {boolean}
|
|
1412
|
+
* @see roughlyEquals
|
|
1386
1413
|
*/
|
|
1387
1414
|
equals(other) {
|
|
1388
1415
|
return this.x === other.x
|
|
@@ -1411,7 +1438,10 @@ export class Quaternion {
|
|
|
1411
1438
|
* @return {boolean}
|
|
1412
1439
|
*/
|
|
1413
1440
|
roughlyEquals(other, tolerance) {
|
|
1414
|
-
return this._roughlyEquals(
|
|
1441
|
+
return this._roughlyEquals(
|
|
1442
|
+
other.x, other.y, other.z, other.w,
|
|
1443
|
+
tolerance
|
|
1444
|
+
);
|
|
1415
1445
|
}
|
|
1416
1446
|
|
|
1417
1447
|
/**
|
|
@@ -1420,10 +1450,12 @@ export class Quaternion {
|
|
|
1420
1450
|
* @param {number} y
|
|
1421
1451
|
* @param {number} z
|
|
1422
1452
|
* @param {number} w
|
|
1423
|
-
* @param {number} [tolerance]
|
|
1453
|
+
* @param {number} [tolerance] acceptable difference value per coordinate
|
|
1424
1454
|
* @return {boolean}
|
|
1425
1455
|
*/
|
|
1426
1456
|
_roughlyEquals(x, y, z, w, tolerance = EPSILON) {
|
|
1457
|
+
assert.isNumber(tolerance, 'tolerance');
|
|
1458
|
+
|
|
1427
1459
|
return epsilonEquals(this.x, x, tolerance)
|
|
1428
1460
|
&& epsilonEquals(this.y, y, tolerance)
|
|
1429
1461
|
&& epsilonEquals(this.z, z, tolerance)
|
|
@@ -1446,8 +1478,6 @@ export class Quaternion {
|
|
|
1446
1478
|
const sqrt1u1 = Math.sqrt(1 - u1);
|
|
1447
1479
|
const sqrtu1 = Math.sqrt(u1);
|
|
1448
1480
|
|
|
1449
|
-
const PI2 = 2 * Math.PI;
|
|
1450
|
-
|
|
1451
1481
|
const u2 = PI2 * random();
|
|
1452
1482
|
|
|
1453
1483
|
const u3 = PI2 * random();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Wrapper around a scalar value, `Vector1` is used for consistence with {@link Vector2} and {@link Vector3}
|
|
3
|
+
*
|
|
2
4
|
* @author Alex Goldring
|
|
3
5
|
* @copyright Company Named Limited (c) 2025
|
|
4
6
|
*/
|
|
@@ -19,7 +21,11 @@ export class Vector1 extends Number {
|
|
|
19
21
|
*/
|
|
20
22
|
constructor(x?: number);
|
|
21
23
|
x: number;
|
|
22
|
-
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @type {Signal<number,number>}
|
|
27
|
+
*/
|
|
28
|
+
onChanged: Signal<number, number>;
|
|
23
29
|
/**
|
|
24
30
|
*
|
|
25
31
|
* @returns {string}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vector1.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector1.js"],"names":[],"mappings":"AAKA
|
|
1
|
+
{"version":3,"file":"Vector1.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector1.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH;IAgRI;;;;;OAKG;IACH,kBAJW,OAAO,KACP,OAAO,GACN,MAAM,CAIjB;IAvRD;;;;;;OAMG;IACH,gBALW,MAAM,EAkBhB;IAPG,UAAU;IAEV;;;OAGG;IACH,WAFU,MAAM,CAAC,MAAM,EAAC,MAAM,CAAC,CAEF;IAWjC;;;OAGG;IACH,YAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,YAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,iBAHW,OAAO,GACL,MAAM,CAIlB;IAED;;;;OAIG;IACH,OAHW,MAAM,GACJ,OAAO,CAgBnB;IAED;;;OAGG;IACH,aAFW,MAAM,QAOhB;IAED;;;OAGG;IACH,UAFY,OAAO,CAIlB;IAED;;;OAGG;IACH,kBAEC;IAED;;;OAGG;IACH,kBAEC;IAED;;;;OAIG;IACH,iBAFY,OAAO,CAIlB;IAED;;;OAGG;IACH,WAFW,OAAO,GAAC,OAAO,GAAC,OAAO,GAAC,OAAO,WAKzC;IAED;;;;OAIG;IACH,iBAFY,OAAO,CAIlB;IAED;;;;OAIG;IACH,WAHW,OAAO,GACL,OAAO,CAInB;IAED;;;;OAIG;IACH,gBAHW,OAAO,GACL,OAAO,CAInB;IAED;;;OAGG;IACH,kBAFW,MAAM,QAIhB;IAED;;;;;OAKG;IACH,WAJW,MAAM,QACN,MAAM,GACJ,OAAO,CAInB;IAED;;;OAGG;IACH,eAEC;IAED;;;OAGG;IACH,YAFW,OAAO,GAAC,OAAO,GAAC,OAAO,GAAC,OAAO,QAIzC;IAED;;;OAGG;IACH,SAFa,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,OAAO,GACL,OAAO,CAInB;IAED;;OAEG;IACH,QAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,4BAGC;IAED,iBAEC;IAED,yBAEC;IAED;;;;OAIG;IACH,qBAHW,MAAM,EAAE,WACR,MAAM,QAIhB;IAED;;;;OAIG;IACH,oBAHW,MAAM,EAAE,WACR,MAAM,QAIhB;IAED,oBAEC;IAED;;;OAGG;IACH,uBAFW,YAAY,QAItB;IAED;;;OAGG;IACH,yBAFW,YAAY,QAMtB;IAkBD,iBAEC;IAND,gBAEC;IAaL;;;OAGG;IACH,oBAFU,OAAO,CAEU;IAXvB,sDAIC;CACJ;;kBAUS,MAAM;cAON,OAAO;aAOP,OAAO;;;mBA3UE,4BAA4B"}
|
package/src/core/geom/Vector1.js
CHANGED
|
@@ -4,6 +4,8 @@ import { clamp } from "../math/clamp.js";
|
|
|
4
4
|
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
+
* Wrapper around a scalar value, `Vector1` is used for consistence with {@link Vector2} and {@link Vector3}
|
|
8
|
+
*
|
|
7
9
|
* @author Alex Goldring
|
|
8
10
|
* @copyright Company Named Limited (c) 2025
|
|
9
11
|
*/
|
|
@@ -23,6 +25,10 @@ export class Vector1 extends Number {
|
|
|
23
25
|
|
|
24
26
|
this.x = x;
|
|
25
27
|
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @type {Signal<number,number>}
|
|
31
|
+
*/
|
|
26
32
|
this.onChanged = new Signal();
|
|
27
33
|
}
|
|
28
34
|
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent a number of things, such as:
|
|
3
|
+
*
|
|
4
|
+
* A point in 2D space (i.e. a position on a plane).
|
|
5
|
+
* A direction and length across a plane. The length will always be the Euclidean distance (straight-line distance) from `(0, 0)` to `(x, y)` and the direction is also measured from `(0, 0)` towards `(x, y)`.
|
|
6
|
+
* Any arbitrary ordered pair of numbers.
|
|
7
|
+
* There are other things a 2D vector can be used to represent, such as momentum vectors, complex numbers and so on, however these are the most common uses.
|
|
8
|
+
*
|
|
9
|
+
* Iterating through a Vector2 instance will yield its components `(x, y)` in the corresponding order.
|
|
10
|
+
*
|
|
11
|
+
* @implements Iterable<number>
|
|
2
12
|
*
|
|
3
13
|
* @author Alex Goldring
|
|
4
14
|
* @copyright Company Named Limited (c) 2025
|
|
5
15
|
*/
|
|
6
|
-
export class Vector2 {
|
|
16
|
+
export class Vector2 implements Iterable<number> {
|
|
7
17
|
/**
|
|
8
18
|
*
|
|
9
19
|
* @param {number} [x=0]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vector2.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector2.js"],"names":[],"mappings":"AAcA
|
|
1
|
+
{"version":3,"file":"Vector2.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector2.js"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;GAcG;AACH,gCALe,QAAQ,CAAC,MAAM;IAM1B;;;;OAIG;IACH,gBAHW,MAAM,MACN,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,KACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;OAIG;IACH,2BAHW,OAAO,GACL,MAAM,CAOlB;IAED;;OAEG;IACH,UAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,aAFa,IAAI,CAahB;IAGD;;;OAGG;IACH,QAFa,MAAM,CAOlB;IAED;;;;OAIG;IACH,cAHW,MAAM,GACJ,IAAI,CAahB;IAED;;;;;OAKG;IACH,uCAHW,GAAC,GACC,IAAI,CAQhB;IAED,mBAEC;IAED;;;;OAIG;IACH,cAHW,OAAO,GACL,OAAO,CAMnB;IAED;;;;;OAKG;IACH,qBAJW,OAAO,cACP,MAAM,GACL,OAAO,CAIlB;IAED;;;;;;OAMG;IACH,kBALW,MAAM,KACN,MAAM,cACN,MAAM,GACL,OAAO,CAKlB;IAUD,iBAEC;IAVD,gBAEC;IAUD,iBAEC;IAVD,gBAEC;IAsDL;;OAEG;IACH,sBAvoBe,MAAM,EAAE,GAAC,YAAY,WACrB,MAAM,UAsoBS;IAE9B;;OAEG;IACH,uBAzpBe,MAAM,EAAE,GAAC,YAAY,WACrB,MAAM,aAwpBU;IAG/B;;;OAGG;IACH,oBAFU,OAAO,CAEU;IA1DvB,sDAKC;CACJ;;mBAIS,OAAO;qBAMP,OAAO;qBAMP,OAAO;sBAMP,OAAO;qBAMP,OAAO;oBAKP,OAAO;;yBAsBP,MAAM;;;mBAjuBG,4BAA4B;4BAQnB,uBAAuB"}
|
package/src/core/geom/Vector2.js
CHANGED
|
@@ -13,6 +13,16 @@ import { v2_length } from "./vec2/v2_length.js";
|
|
|
13
13
|
import { v2_length_sqr } from "./vec2/v2_length_sqr.js";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
+
* Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent a number of things, such as:
|
|
17
|
+
*
|
|
18
|
+
* A point in 2D space (i.e. a position on a plane).
|
|
19
|
+
* A direction and length across a plane. The length will always be the Euclidean distance (straight-line distance) from `(0, 0)` to `(x, y)` and the direction is also measured from `(0, 0)` towards `(x, y)`.
|
|
20
|
+
* Any arbitrary ordered pair of numbers.
|
|
21
|
+
* There are other things a 2D vector can be used to represent, such as momentum vectors, complex numbers and so on, however these are the most common uses.
|
|
22
|
+
*
|
|
23
|
+
* Iterating through a Vector2 instance will yield its components `(x, y)` in the corresponding order.
|
|
24
|
+
*
|
|
25
|
+
* @implements Iterable<number>
|
|
16
26
|
*
|
|
17
27
|
* @author Alex Goldring
|
|
18
28
|
* @copyright Company Named Limited (c) 2025
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Class representing a 3D vector. A 3D vector is an ordered triplet of numbers (labeled x, y, and z), which can be used to represent a number of things, such as:
|
|
3
|
+
*
|
|
4
|
+
* A point in 3D space.
|
|
5
|
+
* A direction and length in 3D space. The length will always be the Euclidean distance (straight-line distance) from `(0, 0, 0)` to `(x, y, z)` and the direction is also measured from `(0, 0, 0)` towards `(x, y, z)`.
|
|
6
|
+
* Any arbitrary ordered triplet of numbers.
|
|
7
|
+
* There are other things a 3D vector can be used to represent, such as momentum vectors and so on, however these are the most common uses.
|
|
8
|
+
*
|
|
9
|
+
* Iterating through a Vector3 instance will yield its components `(x, y, z)` in the corresponding order.
|
|
10
|
+
*
|
|
11
|
+
* @implements Iterable<number>
|
|
2
12
|
*
|
|
3
13
|
* @author Alex Goldring
|
|
4
14
|
* @copyright Company Named Limited (c) 2025
|
|
5
15
|
*/
|
|
6
|
-
export class Vector3 {
|
|
16
|
+
export class Vector3 implements Iterable<number> {
|
|
7
17
|
/**
|
|
8
18
|
* Dot product
|
|
9
19
|
* @param {Vector3|Vector4} a
|
|
@@ -36,7 +46,6 @@ export class Vector3 {
|
|
|
36
46
|
* @param {number} [x=0]
|
|
37
47
|
* @param {number} [y=0]
|
|
38
48
|
* @param {number} [z=0]
|
|
39
|
-
* @constructor
|
|
40
49
|
*/
|
|
41
50
|
constructor(x?: number, y?: number, z?: number);
|
|
42
51
|
/**
|
|
@@ -58,6 +67,7 @@ export class Vector3 {
|
|
|
58
67
|
*/
|
|
59
68
|
readonly z: number;
|
|
60
69
|
/**
|
|
70
|
+
* Dispatches ( x, y, z, old_x, old_y, old_z )
|
|
61
71
|
* @readonly
|
|
62
72
|
* @type {Signal<number,number,number,number,number,number>}
|
|
63
73
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vector3.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector3.js"],"names":[],"mappings":"AAeA
|
|
1
|
+
{"version":3,"file":"Vector3.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector3.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;GAcG;AACH,gCALe,QAAQ,CAAC,MAAM;IAk/B1B;;;;;OAKG;IACH,cAJW,OAAO,GAAC,OAAO,KACf,OAAO,GAAC,OAAO,GACb,MAAM,CAIlB;IAED;;;;;OAKG;IACH,mBAJW,OAAO,KACP,OAAO,GACL,MAAM,CAIlB;IAED;;;;;OAKG;IACH,wBAJW,MAAM,EAAE,WACR,MAAM,GACJ,OAAO,CAQnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,GACJ,OAAO,CAInB;IArhCD;;;;;OAKG;IACH,gBAJW,MAAM,MACN,MAAM,MACN,MAAM,EAuChB;IA3BG;;;;OAIG;IACH,YAFU,MAAM,CAEN;IAEV;;;;OAIG;IACH,YAFU,MAAM,CAEN;IAEV;;;;OAIG;IACH,YAFU,MAAM,CAEN;IAEV;;;;OAIG;IACH,oBAFU,MAAM,CAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,MAAM,CAAC,CAE9B;IA2BjC;;;OAGG;IACH,SAFW,MAAM,EAIhB;IA9BD;;;OAGG;IACH,SAFY,MAAM,CAIjB;IA0BD;;;OAGG;IACH,SAFW,MAAM,EAIhB;IA9BD;;;OAGG;IACH,SAFY,MAAM,CAIjB;IA0BD;;;OAGG;IACH,SAFW,M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
|
|
|
16
16
|
/**
|
|
17
|
+
* Class representing a 3D vector. A 3D vector is an ordered triplet of numbers (labeled x, y, and z), which can be used to represent a number of things, such as:
|
|
18
|
+
*
|
|
19
|
+
* A point in 3D space.
|
|
20
|
+
* A direction and length in 3D space. The length will always be the Euclidean distance (straight-line distance) from `(0, 0, 0)` to `(x, y, z)` and the direction is also measured from `(0, 0, 0)` towards `(x, y, z)`.
|
|
21
|
+
* Any arbitrary ordered triplet of numbers.
|
|
22
|
+
* There are other things a 3D vector can be used to represent, such as momentum vectors and so on, however these are the most common uses.
|
|
23
|
+
*
|
|
24
|
+
* Iterating through a Vector3 instance will yield its components `(x, y, z)` in the corresponding order.
|
|
25
|
+
*
|
|
26
|
+
* @implements Iterable<number>
|
|
17
27
|
*
|
|
18
28
|
* @author Alex Goldring
|
|
19
29
|
* @copyright Company Named Limited (c) 2025
|
|
@@ -24,7 +34,6 @@ export class Vector3 {
|
|
|
24
34
|
* @param {number} [x=0]
|
|
25
35
|
* @param {number} [y=0]
|
|
26
36
|
* @param {number} [z=0]
|
|
27
|
-
* @constructor
|
|
28
37
|
*/
|
|
29
38
|
constructor(x = 0, y = 0, z = 0) {
|
|
30
39
|
assert.isNumber(x, 'x');
|
|
@@ -58,6 +67,7 @@ export class Vector3 {
|
|
|
58
67
|
this.z = z;
|
|
59
68
|
|
|
60
69
|
/**
|
|
70
|
+
* Dispatches ( x, y, z, old_x, old_y, old_z )
|
|
61
71
|
* @readonly
|
|
62
72
|
* @type {Signal<number,number,number,number,number,number>}
|
|
63
73
|
*/
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Class representing a 4D vector. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w), which can be used to represent a number of things, such as:
|
|
3
|
+
*
|
|
4
|
+
* A point in 4D space.
|
|
5
|
+
* A direction and length in 4D space. The length will always be the Euclidean distance (straight-line distance) from `(0, 0, 0, 0)` to `(x, y, z, w)` and the direction is also measured from `(0, 0, 0, 0)` towards `(x, y, z, w)`.
|
|
6
|
+
* Any arbitrary ordered quadruplet of numbers.
|
|
7
|
+
* There are other things a 4D vector can be used to represent, however these are the most common uses.
|
|
8
|
+
*
|
|
9
|
+
* Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.
|
|
10
|
+
*
|
|
11
|
+
* @implements Iterable<number>
|
|
12
|
+
*/
|
|
13
|
+
export class Vector4 implements Iterable<number> {
|
|
2
14
|
/**
|
|
3
15
|
*
|
|
4
16
|
* @param {Vector4} v0
|
|
@@ -149,11 +161,17 @@ export class Vector4 {
|
|
|
149
161
|
*/
|
|
150
162
|
add3(v3: Vector3 | Vector4): Vector4;
|
|
151
163
|
/**
|
|
152
|
-
*
|
|
164
|
+
* @deprecated use {@link applyMatrix4} directly instead
|
|
153
165
|
* @param {Matrix4} m
|
|
154
166
|
* @returns {Vector4} this
|
|
155
167
|
*/
|
|
156
168
|
threeApplyMatrix4(m: Matrix4): Vector4;
|
|
169
|
+
/**
|
|
170
|
+
*
|
|
171
|
+
* @param {number[]|Float32Array} m 4x4 transformation matrix
|
|
172
|
+
* @return {Vector4}
|
|
173
|
+
*/
|
|
174
|
+
applyMatrix4(m: number[] | Float32Array): Vector4;
|
|
157
175
|
/**
|
|
158
176
|
*
|
|
159
177
|
* @param {Vector4} vec4
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Vector4.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector4.js"],"names":[],"mappings":"AAMA;
|
|
1
|
+
{"version":3,"file":"Vector4.d.ts","sourceRoot":"","sources":["../../../../src/core/geom/Vector4.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AACH,gCAFe,QAAQ,CAAC,MAAM;IAgc1B;;;;;;OAMG;IACH,gBALW,OAAO,MACP,OAAO,qBAEP,OAAO,QASjB;IA3cD;;;;;;;;OAQG;IACH,gBAPW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,EAsCh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InB;IAED;;;;OAIG;IACH,gBAHW,MAAM,EAAE,GAAC,YAAY,GACpB,OAAO,CASlB;IAED;;;;OAIG;IACH,WAHW,OAAO,GACL,OAAO,CAInB;IAED;;;OAGG;IACH,SAFa,OAAO,CAQnB;IAED;;;OAGG;IACH,mBAFW,UAAU,QAyBpB;IAED;;;;OAIG;IACH,aAHW,OAAO,GACL,OAAO,CAInB;IAED;;;OAGG;IACH,QAFY,MAAM,CASjB;IAED;;;;OAIG;IACH,gBAJW,OAAO,MACP,OAAO,mBAKjB;IAuGL,kBAnGe,MAAM,EAAE,UAmGE;IA1FrB;;OAEG;IACH,WAFa,MAAM,EAAE,CAQpB;IAED;;;;OAIG;IACH,mBAHW,MAAM,EAAE,UACR,MAAM,QAIhB;IAED;;;;;MAOC;IAED,0BAEC;IAED;;;OAGG;IACH,uBAFW,YAAY,QAOtB;IAED;;;OAGG;IACH,yBAFW,YAAY,QAStB;IA4BL;;;OAGG;IACH,oBAFU,OAAO,CAEU;IAE3B,mBArWe,MAAM,EAAE,WACR,MAAM,UAoWM;IAhCvB,sDAOC;CAiBJ;;kBAaS,MAAM"}
|
package/src/core/geom/Vector4.js
CHANGED
|
@@ -4,6 +4,18 @@ import { Signal } from "../events/signal/Signal.js";
|
|
|
4
4
|
import { lerp } from "../math/lerp.js";
|
|
5
5
|
import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Class representing a 4D vector. A 4D vector is an ordered quadruplet of numbers (labeled x, y, z, and w), which can be used to represent a number of things, such as:
|
|
9
|
+
*
|
|
10
|
+
* A point in 4D space.
|
|
11
|
+
* A direction and length in 4D space. The length will always be the Euclidean distance (straight-line distance) from `(0, 0, 0, 0)` to `(x, y, z, w)` and the direction is also measured from `(0, 0, 0, 0)` towards `(x, y, z, w)`.
|
|
12
|
+
* Any arbitrary ordered quadruplet of numbers.
|
|
13
|
+
* There are other things a 4D vector can be used to represent, however these are the most common uses.
|
|
14
|
+
*
|
|
15
|
+
* Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.
|
|
16
|
+
*
|
|
17
|
+
* @implements Iterable<number>
|
|
18
|
+
*/
|
|
7
19
|
export class Vector4 {
|
|
8
20
|
/**
|
|
9
21
|
*
|
|
@@ -270,17 +282,25 @@ export class Vector4 {
|
|
|
270
282
|
}
|
|
271
283
|
|
|
272
284
|
/**
|
|
273
|
-
*
|
|
285
|
+
* @deprecated use {@link applyMatrix4} directly instead
|
|
274
286
|
* @param {Matrix4} m
|
|
275
287
|
* @returns {Vector4} this
|
|
276
288
|
*/
|
|
277
289
|
threeApplyMatrix4(m) {
|
|
278
|
-
|
|
290
|
+
return this.applyMatrix4(m.elements);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
*
|
|
295
|
+
* @param {number[]|Float32Array} m 4x4 transformation matrix
|
|
296
|
+
* @return {Vector4}
|
|
297
|
+
*/
|
|
298
|
+
applyMatrix4(m) {
|
|
279
299
|
return this._applyMatrix4(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
300
|
+
m[0], m[1], m[2], m[3],
|
|
301
|
+
m[4], m[5], m[6], m[7],
|
|
302
|
+
m[8], m[9], m[10], m[11],
|
|
303
|
+
m[12], m[13], m[14], m[15]
|
|
284
304
|
);
|
|
285
305
|
}
|
|
286
306
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]} output 3x3 rotation matrix
|
|
4
|
+
* @param {Vector3} forward
|
|
5
|
+
* @param {Vector3} up_dir
|
|
6
|
+
*/
|
|
7
|
+
export function m3_make_rotation_TBN(output: number[], forward: Vector3, up_dir: Vector3): void;
|
|
8
|
+
import Vector3 from "../Vector3.js";
|
|
9
|
+
//# sourceMappingURL=m3_make_rotation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"m3_make_rotation.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/mat3/m3_make_rotation.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,6CAJW,MAAM,EAAE,WACR,OAAO,UACP,OAAO,QAqBjB;oBA9BmB,eAAe"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Vector3 from "../Vector3.js";
|
|
2
|
+
|
|
3
|
+
const v3_scratch_1 = new Vector3();
|
|
4
|
+
const v3_scratch_2 = new Vector3();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {number[]} output 3x3 rotation matrix
|
|
9
|
+
* @param {Vector3} forward
|
|
10
|
+
* @param {Vector3} up_dir
|
|
11
|
+
*/
|
|
12
|
+
export function m3_make_rotation_TBN(output, forward, up_dir) {
|
|
13
|
+
output[6] = forward.x;
|
|
14
|
+
output[7] = forward.y;
|
|
15
|
+
output[8] = forward.z;
|
|
16
|
+
|
|
17
|
+
v3_scratch_2.set(output[6], output[7], output[8]);
|
|
18
|
+
v3_scratch_1.crossVectors(up_dir, v3_scratch_2);
|
|
19
|
+
v3_scratch_1.normalize();
|
|
20
|
+
|
|
21
|
+
output[0] = v3_scratch_1.x;
|
|
22
|
+
output[1] = v3_scratch_1.y;
|
|
23
|
+
output[2] = v3_scratch_1.z;
|
|
24
|
+
|
|
25
|
+
v3_scratch_1.crossVectors(v3_scratch_2, v3_scratch_1);
|
|
26
|
+
v3_scratch_1.normalize();
|
|
27
|
+
|
|
28
|
+
output[3] = v3_scratch_1.x;
|
|
29
|
+
output[4] = v3_scratch_1.y;
|
|
30
|
+
output[5] = v3_scratch_1.z;
|
|
31
|
+
}
|