aether-physics 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +79 -3
- package/dist/index.js +56 -0
- package/dist/math-DrI-pge3.js +502 -0
- package/dist/math.js +1 -0
- package/dist/types/engine/loop.d.ts +37 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/math/geometry/mat3x3.d.ts +270 -0
- package/dist/types/math/geometry/mat3x4.d.ts +338 -0
- package/dist/types/math/geometry/quaternion.d.ts +377 -0
- package/dist/types/math/geometry/vec3.d.ts +171 -0
- package/dist/types/math/index.d.ts +6 -0
- package/dist/types/math/scalar.d.ts +3 -0
- package/dist/types/math/types.d.ts +15 -0
- package/package.json +48 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Brandon Berisford
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Aether
|
|
2
|
+
|
|
3
|
+
A 3D rigid-body physics engine written from scratch in TypeScript, with a browser playground built on Lit and Three.js.
|
|
4
|
+
|
|
5
|
+
This is a learning project. The engine is built in phases, from vectors to stacking boxes to ragdolls, following Ian Millington's *Game Physics Engine Development*, Erin Catto's solver talks, and the resources collected at [brm.io/game-physics-for-beginners](https://brm.io/game-physics-for-beginners/).
|
|
6
|
+
|
|
7
|
+
- **[docs/PLAN.md](docs/PLAN.md):** the phased build plan, with goals, checklists, tests and demos for each phase
|
|
8
|
+
- **[docs/RESOURCES.md](docs/RESOURCES.md):** books, articles, talks and reference engines for each phase
|
|
9
|
+
- **[docs/DEMOS.md](docs/DEMOS.md):** how to build a demo: templates, using the engine from Three.js, demo controls and UI style
|
|
10
|
+
|
|
11
|
+
**[Try the playground](https://beyondbelief96.github.io/aether/)**. Each push to `main` deploys it to GitHub Pages.
|
|
12
|
+
|
|
13
|
+
## Using the package
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install aether-physics
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { Quaternion, Vec3 } from 'aether-physics';
|
|
21
|
+
|
|
22
|
+
const q = new Quaternion().setFromAxisAngle({ x: 0, y: 1, z: 0 }, Math.PI / 2);
|
|
23
|
+
q.rotateVec3({ x: 1, y: 0, z: 0 }, new Vec3()); // about (0, 0, -1)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
It's early: so far the package has the math library and a fixed-timestep loop. Physics arrives with the later phases below, and the API can change in any 0.x release.
|
|
27
|
+
|
|
28
|
+
## Running it
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install
|
|
32
|
+
npm run dev # playground at http://localhost:5173
|
|
33
|
+
npm test # Vitest in watch mode
|
|
34
|
+
npm run test:run # Vitest once
|
|
35
|
+
npm run typecheck # tsc, no emit
|
|
36
|
+
npm run build # typecheck, then production build of the playground to dist-playground/
|
|
37
|
+
npm run build:lib # build the npm package to dist/
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Keyboard: **Space** pauses, **.** steps once while paused, **R** resets the demo.
|
|
41
|
+
|
|
42
|
+
## Layout
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
src/
|
|
46
|
+
math/ Vec3, Mat3, Mat4, Quat Phase 1
|
|
47
|
+
engine/ game loop, Particle, RigidBody, World Phases 0, 2, 4, 7
|
|
48
|
+
forces/ force generators Phases 3, 4
|
|
49
|
+
collision/ shapes, broadphase, narrowphase Phase 5
|
|
50
|
+
constraints/ contact solver, joints Phases 6, 7
|
|
51
|
+
playground/ the app in the browser, which uses the engine only through "aether-physics"
|
|
52
|
+
demos/ one file per demo (the only engine + Three.js code)
|
|
53
|
+
ui/ Lit components
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Rules
|
|
57
|
+
|
|
58
|
+
- The engine (`math`, `engine`, `forces`, `collision`, `constraints`) never imports `three` or touches the DOM. Demos are the bridge.
|
|
59
|
+
- Physics runs on a fixed timestep; rendering interpolates between steps.
|
|
60
|
+
- TypeScript runs with `erasableSyntaxOnly`: no `enum`, `namespace` or parameter properties.
|
|
61
|
+
- Lit components use `static properties` with `declare` fields and `customElements.define`, never decorators.
|
|
62
|
+
|
|
63
|
+
## Progress
|
|
64
|
+
|
|
65
|
+
| Phase | Topic | Status |
|
|
66
|
+
|---|---|---|
|
|
67
|
+
| 0 | Scaffold and game loop | ✅ |
|
|
68
|
+
| 1 | Math library | ✅ |
|
|
69
|
+
| 2 | Particles and integration | |
|
|
70
|
+
| 3 | Forces, springs and mass aggregates | |
|
|
71
|
+
| 4 | Rigid bodies | |
|
|
72
|
+
| 5 | Collision detection | |
|
|
73
|
+
| 6 | Collision response and friction | |
|
|
74
|
+
| 7 | Joints, sleeping and stability | |
|
|
75
|
+
| 8 | Stretch goals | |
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
[MIT](LICENSE)
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./math-DrI-pge3.js";
|
|
2
|
+
//#region src/engine/loop.ts
|
|
3
|
+
var s = .25, c = class {
|
|
4
|
+
timeScale = 1;
|
|
5
|
+
paused = !1;
|
|
6
|
+
maxStepsPerFrame = 8;
|
|
7
|
+
#e;
|
|
8
|
+
#t = 0;
|
|
9
|
+
#n = null;
|
|
10
|
+
#r = 0;
|
|
11
|
+
#i = 0;
|
|
12
|
+
constructor(e = 60) {
|
|
13
|
+
this.#e = 1 / e;
|
|
14
|
+
}
|
|
15
|
+
get dt() {
|
|
16
|
+
return this.#e;
|
|
17
|
+
}
|
|
18
|
+
get hz() {
|
|
19
|
+
return 1 / this.#e;
|
|
20
|
+
}
|
|
21
|
+
set hz(e) {
|
|
22
|
+
if (!(e > 0)) throw RangeError(`hz must be positive, got ${e}`);
|
|
23
|
+
this.#e = 1 / e;
|
|
24
|
+
}
|
|
25
|
+
get simTime() {
|
|
26
|
+
return this.#r;
|
|
27
|
+
}
|
|
28
|
+
stepOnce() {
|
|
29
|
+
this.#i++;
|
|
30
|
+
}
|
|
31
|
+
reset() {
|
|
32
|
+
this.#t = 0, this.#n = null, this.#r = 0, this.#i = 0;
|
|
33
|
+
}
|
|
34
|
+
advance(e, t) {
|
|
35
|
+
let n = this.#n;
|
|
36
|
+
this.#n = e;
|
|
37
|
+
let r = n === null ? 0 : Math.min((e - n) / 1e3, s), i = 0, a = () => {
|
|
38
|
+
t(this.#e), this.#r += this.#e, i++;
|
|
39
|
+
};
|
|
40
|
+
for (; this.#i > 0; this.#i--) a();
|
|
41
|
+
if (this.paused) return {
|
|
42
|
+
steps: i,
|
|
43
|
+
alpha: 1,
|
|
44
|
+
droppedTime: !1
|
|
45
|
+
};
|
|
46
|
+
for (this.#t += r * this.timeScale; this.#t >= this.#e && i < this.maxStepsPerFrame;) a(), this.#t -= this.#e;
|
|
47
|
+
let o = !1;
|
|
48
|
+
return this.#t >= this.#e && (this.#t %= this.#e, o = !0), {
|
|
49
|
+
steps: i,
|
|
50
|
+
alpha: this.#t / this.#e,
|
|
51
|
+
droppedTime: o
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { e as EPSILON, c as FixedStepLoop, i as Mat3x3, n as Mat3x4, o as Quaternion, t as Vec3, r as approxEqual, a as clamp };
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
//#region src/math/scalar.ts
|
|
2
|
+
var e = 1e-6;
|
|
3
|
+
function t(t, n, r = e) {
|
|
4
|
+
if (t === n) return !0;
|
|
5
|
+
let i = Math.abs(t - n);
|
|
6
|
+
return Number.isFinite(i) && i <= r * Math.max(1, Math.abs(t), Math.abs(n));
|
|
7
|
+
}
|
|
8
|
+
function n(e, t, n) {
|
|
9
|
+
return e < t ? t : e > n ? n : e;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/math/geometry/vec3.ts
|
|
13
|
+
var r = class n {
|
|
14
|
+
x;
|
|
15
|
+
y;
|
|
16
|
+
z;
|
|
17
|
+
constructor(e = 0, t = 0, n = 0) {
|
|
18
|
+
this.x = e, this.y = t, this.z = n;
|
|
19
|
+
}
|
|
20
|
+
set(e, t, n) {
|
|
21
|
+
return this.x = e, this.y = t, this.z = n, this;
|
|
22
|
+
}
|
|
23
|
+
copy(e) {
|
|
24
|
+
return this.x = e.x, this.y = e.y, this.z = e.z, this;
|
|
25
|
+
}
|
|
26
|
+
clone() {
|
|
27
|
+
return new n(this.x, this.y, this.z);
|
|
28
|
+
}
|
|
29
|
+
magnitude() {
|
|
30
|
+
return Math.sqrt(this.magnitudeSquared());
|
|
31
|
+
}
|
|
32
|
+
magnitudeSquared() {
|
|
33
|
+
return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
34
|
+
}
|
|
35
|
+
distanceTo(e) {
|
|
36
|
+
return Math.sqrt(this.distanceToSquared(e));
|
|
37
|
+
}
|
|
38
|
+
distanceToSquared(e) {
|
|
39
|
+
let t = this.x - e.x, n = this.y - e.y, r = this.z - e.z;
|
|
40
|
+
return t * t + n * n + r * r;
|
|
41
|
+
}
|
|
42
|
+
add(e) {
|
|
43
|
+
return this.x += e.x, this.y += e.y, this.z += e.z, this;
|
|
44
|
+
}
|
|
45
|
+
subtract(e) {
|
|
46
|
+
return this.x -= e.x, this.y -= e.y, this.z -= e.z, this;
|
|
47
|
+
}
|
|
48
|
+
scale(e) {
|
|
49
|
+
return this.x *= e, this.y *= e, this.z *= e, this;
|
|
50
|
+
}
|
|
51
|
+
addScaled(e, t) {
|
|
52
|
+
return this.x += e.x * t, this.y += e.y * t, this.z += e.z * t, this;
|
|
53
|
+
}
|
|
54
|
+
componentWiseProduct(e) {
|
|
55
|
+
return this.x *= e.x, this.y *= e.y, this.z *= e.z, this;
|
|
56
|
+
}
|
|
57
|
+
negate() {
|
|
58
|
+
return this.x = -this.x, this.y = -this.y, this.z = -this.z, this;
|
|
59
|
+
}
|
|
60
|
+
lerp(e, t) {
|
|
61
|
+
return this.x += (e.x - this.x) * t, this.y += (e.y - this.y) * t, this.z += (e.z - this.z) * t, this;
|
|
62
|
+
}
|
|
63
|
+
equals(n, r = e) {
|
|
64
|
+
return t(this.x, n.x, r) && t(this.y, n.y, r) && t(this.z, n.z, r);
|
|
65
|
+
}
|
|
66
|
+
dot(e) {
|
|
67
|
+
return this.x * e.x + this.y * e.y + this.z * e.z;
|
|
68
|
+
}
|
|
69
|
+
cross(e) {
|
|
70
|
+
return this.crossVectors(this, e);
|
|
71
|
+
}
|
|
72
|
+
crossVectors(e, t) {
|
|
73
|
+
let n = e.x, r = e.y, i = e.z, a = t.x, o = t.y, s = t.z;
|
|
74
|
+
return this.x = r * s - i * o, this.y = i * a - n * s, this.z = n * o - r * a, this;
|
|
75
|
+
}
|
|
76
|
+
static cross(e, t) {
|
|
77
|
+
return new n(e.y * t.z - e.z * t.y, e.z * t.x - e.x * t.z, e.x * t.y - e.y * t.x);
|
|
78
|
+
}
|
|
79
|
+
normalize() {
|
|
80
|
+
let e = this.magnitude();
|
|
81
|
+
return e > 0 ? (this.x /= e, this.y /= e, this.z /= e) : (this.x = 0, this.y = 0, this.z = 0), this;
|
|
82
|
+
}
|
|
83
|
+
}, i = new Float64Array([
|
|
84
|
+
1,
|
|
85
|
+
0,
|
|
86
|
+
0,
|
|
87
|
+
0,
|
|
88
|
+
1,
|
|
89
|
+
0,
|
|
90
|
+
0,
|
|
91
|
+
0,
|
|
92
|
+
1
|
|
93
|
+
]), a = class e {
|
|
94
|
+
elements;
|
|
95
|
+
constructor(e = 1, t = 0, n = 0, r = 0, i = 1, a = 0, o = 0, s = 0, c = 1) {
|
|
96
|
+
this.elements = new Float64Array([
|
|
97
|
+
e,
|
|
98
|
+
t,
|
|
99
|
+
n,
|
|
100
|
+
r,
|
|
101
|
+
i,
|
|
102
|
+
a,
|
|
103
|
+
o,
|
|
104
|
+
s,
|
|
105
|
+
c
|
|
106
|
+
]);
|
|
107
|
+
}
|
|
108
|
+
identity() {
|
|
109
|
+
return this.elements.set(i), this;
|
|
110
|
+
}
|
|
111
|
+
copy(e) {
|
|
112
|
+
return this.elements.set(e.elements), this;
|
|
113
|
+
}
|
|
114
|
+
clone() {
|
|
115
|
+
return new e().copy(this);
|
|
116
|
+
}
|
|
117
|
+
setDiagonal(e, t, n) {
|
|
118
|
+
let r = this.elements;
|
|
119
|
+
return r[0] = e, r[1] = 0, r[2] = 0, r[3] = 0, r[4] = t, r[5] = 0, r[6] = 0, r[7] = 0, r[8] = n, this;
|
|
120
|
+
}
|
|
121
|
+
setScale(e, t = e, n = e) {
|
|
122
|
+
return this.setDiagonal(e, t, n);
|
|
123
|
+
}
|
|
124
|
+
setScaleAlongAxis(e, t) {
|
|
125
|
+
let n = this.elements, r = e.x, i = e.y, a = e.z, o = t - 1;
|
|
126
|
+
return n[0] = 1 + o * r * r, n[1] = o * r * i, n[2] = o * r * a, n[3] = o * r * i, n[4] = 1 + o * i * i, n[5] = o * i * a, n[6] = o * r * a, n[7] = o * i * a, n[8] = 1 + o * a * a, this;
|
|
127
|
+
}
|
|
128
|
+
setReflection(e) {
|
|
129
|
+
return this.setScaleAlongAxis(e, -1);
|
|
130
|
+
}
|
|
131
|
+
setShear(e = 0, t = 0, n = 0, r = 0, i = 0, a = 0) {
|
|
132
|
+
let o = this.elements;
|
|
133
|
+
return o[0] = 1, o[1] = e, o[2] = t, o[3] = n, o[4] = 1, o[5] = r, o[6] = i, o[7] = a, o[8] = 1, this;
|
|
134
|
+
}
|
|
135
|
+
multiplyScalar(e) {
|
|
136
|
+
let t = this.elements;
|
|
137
|
+
return t[0] = e * t[0], t[1] = e * t[1], t[2] = e * t[2], t[3] = e * t[3], t[4] = e * t[4], t[5] = e * t[5], t[6] = e * t[6], t[7] = e * t[7], t[8] = e * t[8], this;
|
|
138
|
+
}
|
|
139
|
+
multiply(e) {
|
|
140
|
+
return this.multiplyMatrices(this, e);
|
|
141
|
+
}
|
|
142
|
+
premultiply(e) {
|
|
143
|
+
return this.multiplyMatrices(e, this);
|
|
144
|
+
}
|
|
145
|
+
multiplyMatrices(e, t) {
|
|
146
|
+
let n = e.elements, r = t.elements, i = n[0], a = n[1], o = n[2], s = n[3], c = n[4], l = n[5], u = n[6], d = n[7], f = n[8], p = r[0], m = r[1], h = r[2], g = r[3], _ = r[4], v = r[5], y = r[6], b = r[7], x = r[8], S = this.elements;
|
|
147
|
+
return S[0] = i * p + a * g + o * y, S[1] = i * m + a * _ + o * b, S[2] = i * h + a * v + o * x, S[3] = s * p + c * g + l * y, S[4] = s * m + c * _ + l * b, S[5] = s * h + c * v + l * x, S[6] = u * p + d * g + f * y, S[7] = u * m + d * _ + f * b, S[8] = u * h + d * v + f * x, this;
|
|
148
|
+
}
|
|
149
|
+
transpose() {
|
|
150
|
+
let e = this.elements, t = e[1], n = e[2], r = e[3], i = e[5], a = e[6], o = e[7];
|
|
151
|
+
return e[1] = r, e[2] = a, e[3] = t, e[5] = o, e[6] = n, e[7] = i, this;
|
|
152
|
+
}
|
|
153
|
+
determinant() {
|
|
154
|
+
let e = this.elements, t = e[0], n = e[1], r = e[2], i = e[3], a = e[4], o = e[5], s = e[6], c = e[7], l = e[8];
|
|
155
|
+
return t * (a * l - o * c) + n * (o * s - i * l) + r * (i * c - a * s);
|
|
156
|
+
}
|
|
157
|
+
setInverse(e) {
|
|
158
|
+
let t = e.elements, n = t[0], r = t[1], i = t[2], a = t[3], o = t[4], s = t[5], c = t[6], l = t[7], u = t[8], d = o * u - s * l, f = s * c - a * u, p = a * l - o * c, m = n * d + r * f + i * p, h = this.elements;
|
|
159
|
+
if (m === 0) return h.fill(0), this;
|
|
160
|
+
let g = 1 / m;
|
|
161
|
+
return h[0] = d * g, h[1] = (i * l - r * u) * g, h[2] = (r * s - i * o) * g, h[3] = f * g, h[4] = (n * u - i * c) * g, h[5] = (i * a - n * s) * g, h[6] = p * g, h[7] = (r * c - n * l) * g, h[8] = (n * o - r * a) * g, this;
|
|
162
|
+
}
|
|
163
|
+
inverse() {
|
|
164
|
+
return this.setInverse(this);
|
|
165
|
+
}
|
|
166
|
+
setInverseOrthonormal(e) {
|
|
167
|
+
let t = e.elements, n = t[0], r = t[1], i = t[2], a = t[3], o = t[4], s = t[5], c = t[6], l = t[7], u = t[8], d = this.elements;
|
|
168
|
+
return d[0] = n, d[1] = a, d[2] = c, d[3] = r, d[4] = o, d[5] = l, d[6] = i, d[7] = s, d[8] = u, this;
|
|
169
|
+
}
|
|
170
|
+
inverseOrthonormal() {
|
|
171
|
+
return this.transpose();
|
|
172
|
+
}
|
|
173
|
+
transformVec3(e, t = new r()) {
|
|
174
|
+
let n = this.elements, i = e.x, a = e.y, o = e.z;
|
|
175
|
+
return t.x = n[0] * i + n[1] * a + n[2] * o, t.y = n[3] * i + n[4] * a + n[5] * o, t.z = n[6] * i + n[7] * a + n[8] * o, t;
|
|
176
|
+
}
|
|
177
|
+
transformInverseVec3(e, t = new r()) {
|
|
178
|
+
let n = this.elements, i = e.x, a = e.y, o = e.z;
|
|
179
|
+
return t.x = n[0] * i + n[3] * a + n[6] * o, t.y = n[1] * i + n[4] * a + n[7] * o, t.z = n[2] * i + n[5] * a + n[8] * o, t;
|
|
180
|
+
}
|
|
181
|
+
setRotationX(e) {
|
|
182
|
+
let t = this.elements, n = Math.sin(e), r = Math.cos(e);
|
|
183
|
+
return t[0] = 1, t[1] = 0, t[2] = 0, t[3] = 0, t[4] = r, t[5] = -n, t[6] = 0, t[7] = n, t[8] = r, this;
|
|
184
|
+
}
|
|
185
|
+
setRotationY(e) {
|
|
186
|
+
let t = this.elements, n = Math.sin(e), r = Math.cos(e);
|
|
187
|
+
return t[0] = r, t[1] = 0, t[2] = n, t[3] = 0, t[4] = 1, t[5] = 0, t[6] = -n, t[7] = 0, t[8] = r, this;
|
|
188
|
+
}
|
|
189
|
+
setRotationZ(e) {
|
|
190
|
+
let t = this.elements, n = Math.sin(e), r = Math.cos(e);
|
|
191
|
+
return t[0] = r, t[1] = -n, t[2] = 0, t[3] = n, t[4] = r, t[5] = 0, t[6] = 0, t[7] = 0, t[8] = 1, this;
|
|
192
|
+
}
|
|
193
|
+
setFromAxisAngle(e, t) {
|
|
194
|
+
let n = e.x, r = e.y, i = e.z, a = Math.cos(t), o = Math.sin(t), s = this.elements, c = 1 - a;
|
|
195
|
+
return s[0] = c * n * n + a, s[1] = n * r * c - i * o, s[2] = n * i * c + r * o, s[3] = n * r * c + i * o, s[4] = a + r * r * c, s[5] = r * i * c - n * o, s[6] = n * i * c - r * o, s[7] = r * i * c + n * o, s[8] = a + i * i * c, this;
|
|
196
|
+
}
|
|
197
|
+
setFromQuaternion(e) {
|
|
198
|
+
let t = e.w, n = e.x, r = e.y, i = e.z, a = n + n, o = r + r, s = i + i, c = n * a, l = r * o, u = i * s, d = n * o, f = n * s, p = r * s, m = t * a, h = t * o, g = t * s, _ = this.elements;
|
|
199
|
+
return _[0] = 1 - (l + u), _[1] = d - g, _[2] = f + h, _[3] = d + g, _[4] = 1 - (c + u), _[5] = p - m, _[6] = f - h, _[7] = p + m, _[8] = 1 - (c + l), this;
|
|
200
|
+
}
|
|
201
|
+
}, o = new Float64Array([
|
|
202
|
+
1,
|
|
203
|
+
0,
|
|
204
|
+
0,
|
|
205
|
+
0,
|
|
206
|
+
0,
|
|
207
|
+
1,
|
|
208
|
+
0,
|
|
209
|
+
0,
|
|
210
|
+
0,
|
|
211
|
+
0,
|
|
212
|
+
1,
|
|
213
|
+
0
|
|
214
|
+
]), s = class e {
|
|
215
|
+
elements;
|
|
216
|
+
constructor(e = 1, t = 0, n = 0, r = 0, i = 0, a = 1, o = 0, s = 0, c = 0, l = 0, u = 1, d = 0) {
|
|
217
|
+
this.elements = new Float64Array([
|
|
218
|
+
e,
|
|
219
|
+
t,
|
|
220
|
+
n,
|
|
221
|
+
r,
|
|
222
|
+
i,
|
|
223
|
+
a,
|
|
224
|
+
o,
|
|
225
|
+
s,
|
|
226
|
+
c,
|
|
227
|
+
l,
|
|
228
|
+
u,
|
|
229
|
+
d
|
|
230
|
+
]);
|
|
231
|
+
}
|
|
232
|
+
identity() {
|
|
233
|
+
return this.elements.set(o), this;
|
|
234
|
+
}
|
|
235
|
+
copy(e) {
|
|
236
|
+
return this.elements.set(e.elements), this;
|
|
237
|
+
}
|
|
238
|
+
clone() {
|
|
239
|
+
return new e().copy(this);
|
|
240
|
+
}
|
|
241
|
+
setFromMat3x3(e, t = {
|
|
242
|
+
x: 0,
|
|
243
|
+
y: 0,
|
|
244
|
+
z: 0
|
|
245
|
+
}) {
|
|
246
|
+
let n = this.elements, r = e.elements;
|
|
247
|
+
return n[0] = r[0], n[1] = r[1], n[2] = r[2], n[3] = t.x, n[4] = r[3], n[5] = r[4], n[6] = r[5], n[7] = t.y, n[8] = r[6], n[9] = r[7], n[10] = r[8], n[11] = t.z, this;
|
|
248
|
+
}
|
|
249
|
+
getMat3x3(e = new a()) {
|
|
250
|
+
let t = this.elements, n = e.elements;
|
|
251
|
+
return n[0] = t[0], n[1] = t[1], n[2] = t[2], n[3] = t[4], n[4] = t[5], n[5] = t[6], n[6] = t[8], n[7] = t[9], n[8] = t[10], e;
|
|
252
|
+
}
|
|
253
|
+
setTranslation(e, t, n) {
|
|
254
|
+
this.elements.set(o);
|
|
255
|
+
let r = this.elements;
|
|
256
|
+
return r[3] = e, r[7] = t, r[11] = n, this;
|
|
257
|
+
}
|
|
258
|
+
getTranslation(e = new r()) {
|
|
259
|
+
let t = this.elements;
|
|
260
|
+
return e.x = t[3], e.y = t[7], e.z = t[11], e;
|
|
261
|
+
}
|
|
262
|
+
getAxis(e, t = new r()) {
|
|
263
|
+
let n = this.elements;
|
|
264
|
+
return t.x = n[e], t.y = n[e + 4], t.z = n[e + 8], t;
|
|
265
|
+
}
|
|
266
|
+
setFromPositionQuaternion(e, t) {
|
|
267
|
+
let n = t.w, r = t.x, i = t.y, a = t.z, o = r + r, s = i + i, c = a + a, l = r * o, u = i * s, d = a * c, f = r * s, p = r * c, m = i * c, h = n * o, g = n * s, _ = n * c, v = this.elements;
|
|
268
|
+
return v[0] = 1 - (u + d), v[1] = f - _, v[2] = p + g, v[3] = e.x, v[4] = f + _, v[5] = 1 - (l + d), v[6] = m - h, v[7] = e.y, v[8] = p - g, v[9] = m + h, v[10] = 1 - (l + u), v[11] = e.z, this;
|
|
269
|
+
}
|
|
270
|
+
setScale(e, t = e, n = e) {
|
|
271
|
+
let r = this.elements;
|
|
272
|
+
return r[0] = e, r[1] = 0, r[2] = 0, r[3] = 0, r[4] = 0, r[5] = t, r[6] = 0, r[7] = 0, r[8] = 0, r[9] = 0, r[10] = n, r[11] = 0, this;
|
|
273
|
+
}
|
|
274
|
+
setScaleAlongAxis(e, t) {
|
|
275
|
+
let n = this.elements, r = e.x, i = e.y, a = e.z, o = t - 1;
|
|
276
|
+
return n[0] = 1 + o * r * r, n[1] = o * r * i, n[2] = o * r * a, n[3] = 0, n[4] = o * r * i, n[5] = 1 + o * i * i, n[6] = o * i * a, n[7] = 0, n[8] = o * r * a, n[9] = o * i * a, n[10] = 1 + o * a * a, n[11] = 0, this;
|
|
277
|
+
}
|
|
278
|
+
setReflection(e) {
|
|
279
|
+
return this.setScaleAlongAxis(e, -1);
|
|
280
|
+
}
|
|
281
|
+
setShear(e = 0, t = 0, n = 0, r = 0, i = 0, a = 0) {
|
|
282
|
+
let o = this.elements;
|
|
283
|
+
return o[0] = 1, o[1] = e, o[2] = t, o[3] = 0, o[4] = n, o[5] = 1, o[6] = r, o[7] = 0, o[8] = i, o[9] = a, o[10] = 1, o[11] = 0, this;
|
|
284
|
+
}
|
|
285
|
+
multiplyScalar(e) {
|
|
286
|
+
let t = this.elements;
|
|
287
|
+
return t[0] = e * t[0], t[1] = e * t[1], t[2] = e * t[2], t[3] = e * t[3], t[4] = e * t[4], t[5] = e * t[5], t[6] = e * t[6], t[7] = e * t[7], t[8] = e * t[8], t[9] = e * t[9], t[10] = e * t[10], t[11] = e * t[11], this;
|
|
288
|
+
}
|
|
289
|
+
multiply(e) {
|
|
290
|
+
return this.multiplyMatrices(this, e);
|
|
291
|
+
}
|
|
292
|
+
premultiply(e) {
|
|
293
|
+
return this.multiplyMatrices(e, this);
|
|
294
|
+
}
|
|
295
|
+
multiplyMatrices(e, t) {
|
|
296
|
+
let n = e.elements, r = t.elements, i = n[0], a = n[1], o = n[2], s = n[3], c = n[4], l = n[5], u = n[6], d = n[7], f = n[8], p = n[9], m = n[10], h = n[11], g = r[0], _ = r[1], v = r[2], y = r[3], b = r[4], x = r[5], S = r[6], C = r[7], w = r[8], T = r[9], E = r[10], D = r[11], O = this.elements;
|
|
297
|
+
return O[0] = i * g + a * b + o * w, O[1] = i * _ + a * x + o * T, O[2] = i * v + a * S + o * E, O[3] = i * y + a * C + o * D + s, O[4] = c * g + l * b + u * w, O[5] = c * _ + l * x + u * T, O[6] = c * v + l * S + u * E, O[7] = c * y + l * C + u * D + d, O[8] = f * g + p * b + m * w, O[9] = f * _ + p * x + m * T, O[10] = f * v + p * S + m * E, O[11] = f * y + p * C + m * D + h, this;
|
|
298
|
+
}
|
|
299
|
+
transposeLinear() {
|
|
300
|
+
let e = this.elements, t = e[1], n = e[2], r = e[4], i = e[6], a = e[8], o = e[9];
|
|
301
|
+
return e[1] = r, e[2] = a, e[4] = t, e[6] = o, e[8] = n, e[9] = i, this;
|
|
302
|
+
}
|
|
303
|
+
determinant() {
|
|
304
|
+
let e = this.elements, t = e[0], n = e[1], r = e[2], i = e[4], a = e[5], o = e[6], s = e[8], c = e[9], l = e[10];
|
|
305
|
+
return t * (a * l - o * c) + n * (o * s - i * l) + r * (i * c - a * s);
|
|
306
|
+
}
|
|
307
|
+
setInverse(e) {
|
|
308
|
+
let t = e.elements, n = t[0], r = t[1], i = t[2], a = t[3], o = t[4], s = t[5], c = t[6], l = t[7], u = t[8], d = t[9], f = t[10], p = t[11], m = s * f - c * d, h = c * u - o * f, g = o * d - s * u, _ = n * m + r * h + i * g, v = this.elements;
|
|
309
|
+
if (_ === 0) return v.fill(0), this;
|
|
310
|
+
let y = 1 / _, b = m * y, x = (i * d - r * f) * y, S = (r * c - i * s) * y, C = h * y, w = (n * f - i * u) * y, T = (i * o - n * c) * y, E = g * y, D = (r * u - n * d) * y, O = (n * s - r * o) * y;
|
|
311
|
+
return v[0] = b, v[1] = x, v[2] = S, v[3] = -(b * a + x * l + S * p), v[4] = C, v[5] = w, v[6] = T, v[7] = -(C * a + w * l + T * p), v[8] = E, v[9] = D, v[10] = O, v[11] = -(E * a + D * l + O * p), this;
|
|
312
|
+
}
|
|
313
|
+
inverse() {
|
|
314
|
+
return this.setInverse(this);
|
|
315
|
+
}
|
|
316
|
+
setInverseOrthonormal(e) {
|
|
317
|
+
let t = e.elements, n = t[0], r = t[1], i = t[2], a = t[3], o = t[4], s = t[5], c = t[6], l = t[7], u = t[8], d = t[9], f = t[10], p = t[11], m = this.elements;
|
|
318
|
+
return m[0] = n, m[1] = o, m[2] = u, m[3] = -(n * a + o * l + u * p), m[4] = r, m[5] = s, m[6] = d, m[7] = -(r * a + s * l + d * p), m[8] = i, m[9] = c, m[10] = f, m[11] = -(i * a + c * l + f * p), this;
|
|
319
|
+
}
|
|
320
|
+
inverseOrthonormal() {
|
|
321
|
+
return this.setInverseOrthonormal(this);
|
|
322
|
+
}
|
|
323
|
+
transformPoint(e, t = new r()) {
|
|
324
|
+
let n = this.elements, i = e.x, a = e.y, o = e.z;
|
|
325
|
+
return t.x = n[0] * i + n[1] * a + n[2] * o + n[3], t.y = n[4] * i + n[5] * a + n[6] * o + n[7], t.z = n[8] * i + n[9] * a + n[10] * o + n[11], t;
|
|
326
|
+
}
|
|
327
|
+
transformDirection(e, t = new r()) {
|
|
328
|
+
let n = this.elements, i = e.x, a = e.y, o = e.z;
|
|
329
|
+
return t.x = n[0] * i + n[1] * a + n[2] * o, t.y = n[4] * i + n[5] * a + n[6] * o, t.z = n[8] * i + n[9] * a + n[10] * o, t;
|
|
330
|
+
}
|
|
331
|
+
transformInversePoint(e, t = new r()) {
|
|
332
|
+
let n = this.elements, i = e.x - n[3], a = e.y - n[7], o = e.z - n[11];
|
|
333
|
+
return t.x = n[0] * i + n[4] * a + n[8] * o, t.y = n[1] * i + n[5] * a + n[9] * o, t.z = n[2] * i + n[6] * a + n[10] * o, t;
|
|
334
|
+
}
|
|
335
|
+
transformInverseDirection(e, t = new r()) {
|
|
336
|
+
let n = this.elements, i = e.x, a = e.y, o = e.z;
|
|
337
|
+
return t.x = n[0] * i + n[4] * a + n[8] * o, t.y = n[1] * i + n[5] * a + n[9] * o, t.z = n[2] * i + n[6] * a + n[10] * o, t;
|
|
338
|
+
}
|
|
339
|
+
setRotationX(e) {
|
|
340
|
+
let t = this.elements, n = Math.sin(e), r = Math.cos(e);
|
|
341
|
+
return t[0] = 1, t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = r, t[6] = -n, t[7] = 0, t[8] = 0, t[9] = n, t[10] = r, t[11] = 0, this;
|
|
342
|
+
}
|
|
343
|
+
setRotationY(e) {
|
|
344
|
+
let t = this.elements, n = Math.sin(e), r = Math.cos(e);
|
|
345
|
+
return t[0] = r, t[1] = 0, t[2] = n, t[3] = 0, t[4] = 0, t[5] = 1, t[6] = 0, t[7] = 0, t[8] = -n, t[9] = 0, t[10] = r, t[11] = 0, this;
|
|
346
|
+
}
|
|
347
|
+
setRotationZ(e) {
|
|
348
|
+
let t = this.elements, n = Math.sin(e), r = Math.cos(e);
|
|
349
|
+
return t[0] = r, t[1] = -n, t[2] = 0, t[3] = 0, t[4] = n, t[5] = r, t[6] = 0, t[7] = 0, t[8] = 0, t[9] = 0, t[10] = 1, t[11] = 0, this;
|
|
350
|
+
}
|
|
351
|
+
setFromAxisAngle(e, t) {
|
|
352
|
+
let n = e.x, r = e.y, i = e.z, a = Math.cos(t), o = Math.sin(t), s = this.elements, c = 1 - a;
|
|
353
|
+
return s[0] = c * n * n + a, s[1] = n * r * c - i * o, s[2] = n * i * c + r * o, s[3] = 0, s[4] = n * r * c + i * o, s[5] = a + r * r * c, s[6] = r * i * c - n * o, s[7] = 0, s[8] = n * i * c - r * o, s[9] = r * i * c + n * o, s[10] = a + i * i * c, s[11] = 0, this;
|
|
354
|
+
}
|
|
355
|
+
}, c = .9999, l = 1e-12, u = .9999999, d = class n {
|
|
356
|
+
w;
|
|
357
|
+
x;
|
|
358
|
+
y;
|
|
359
|
+
z;
|
|
360
|
+
constructor(e = 1, t = 0, n = 0, r = 0) {
|
|
361
|
+
this.w = e, this.x = t, this.y = n, this.z = r;
|
|
362
|
+
}
|
|
363
|
+
identity() {
|
|
364
|
+
return this.w = 1, this.x = 0, this.y = 0, this.z = 0, this;
|
|
365
|
+
}
|
|
366
|
+
set(e, t, n, r) {
|
|
367
|
+
return this.w = e, this.x = t, this.y = n, this.z = r, this;
|
|
368
|
+
}
|
|
369
|
+
equals(n, r = e) {
|
|
370
|
+
return t(this.w, n.w, r) && t(this.x, n.x, r) && t(this.y, n.y, r) && t(this.z, n.z, r);
|
|
371
|
+
}
|
|
372
|
+
equalsRotation(n, r = e) {
|
|
373
|
+
let i = this.dot(n) < 0 ? -1 : 1;
|
|
374
|
+
return t(this.w, i * n.w, r) && t(this.x, i * n.x, r) && t(this.y, i * n.y, r) && t(this.z, i * n.z, r);
|
|
375
|
+
}
|
|
376
|
+
copy(e) {
|
|
377
|
+
return this.w = e.w, this.x = e.x, this.y = e.y, this.z = e.z, this;
|
|
378
|
+
}
|
|
379
|
+
clone() {
|
|
380
|
+
return new n(this.w, this.x, this.y, this.z);
|
|
381
|
+
}
|
|
382
|
+
magnitudeSquared() {
|
|
383
|
+
return this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z;
|
|
384
|
+
}
|
|
385
|
+
magnitude() {
|
|
386
|
+
return Math.sqrt(this.magnitudeSquared());
|
|
387
|
+
}
|
|
388
|
+
normalize() {
|
|
389
|
+
let e = this.magnitude();
|
|
390
|
+
return e === 0 ? this.identity() : (this.w /= e, this.x /= e, this.y /= e, this.z /= e, this);
|
|
391
|
+
}
|
|
392
|
+
scale(e) {
|
|
393
|
+
return this.w *= e, this.x *= e, this.y *= e, this.z *= e, this;
|
|
394
|
+
}
|
|
395
|
+
dot(e) {
|
|
396
|
+
return this.w * e.w + this.x * e.x + this.y * e.y + this.z * e.z;
|
|
397
|
+
}
|
|
398
|
+
conjugate() {
|
|
399
|
+
return this.x = -this.x, this.y = -this.y, this.z = -this.z, this;
|
|
400
|
+
}
|
|
401
|
+
inverse() {
|
|
402
|
+
let e = this.magnitudeSquared();
|
|
403
|
+
if (e === 0) return this;
|
|
404
|
+
let t = 1 / e;
|
|
405
|
+
return this.w *= t, this.x *= -t, this.y *= -t, this.z *= -t, this;
|
|
406
|
+
}
|
|
407
|
+
log() {
|
|
408
|
+
let e = this.w, t = this.x, n = this.y, r = this.z, i = t * t + n * n + r * r, a = Math.sqrt(i);
|
|
409
|
+
if (this.w = .5 * Math.log(e * e + i), a === 0) return this.x = e < 0 ? Math.PI : 0, this.y = 0, this.z = 0, this;
|
|
410
|
+
let o = Math.atan2(a, e) / a;
|
|
411
|
+
return this.x = o * t, this.y = o * n, this.z = o * r, this;
|
|
412
|
+
}
|
|
413
|
+
exp() {
|
|
414
|
+
let e = this.x, t = this.y, n = this.z, r = Math.sqrt(e * e + t * t + n * n), i = Math.exp(this.w), a = r === 0 ? i : i * Math.sin(r) / r;
|
|
415
|
+
return this.w = i * Math.cos(r), this.x = a * e, this.y = a * t, this.z = a * n, this;
|
|
416
|
+
}
|
|
417
|
+
multiply(e) {
|
|
418
|
+
return this.multiplyQuaternions(this, e);
|
|
419
|
+
}
|
|
420
|
+
premultiply(e) {
|
|
421
|
+
return this.multiplyQuaternions(e, this);
|
|
422
|
+
}
|
|
423
|
+
multiplyQuaternions(e, t) {
|
|
424
|
+
let n = e.w, r = e.x, i = e.y, a = e.z, o = t.w, s = t.x, c = t.y, l = t.z;
|
|
425
|
+
return this.w = n * o - (r * s + i * c + a * l), this.x = n * s + o * r + (i * l - a * c), this.y = n * c + o * i + (a * s - r * l), this.z = n * l + o * a + (r * c - i * s), this;
|
|
426
|
+
}
|
|
427
|
+
setFromAxisAngle(e, t) {
|
|
428
|
+
let n = e.x, r = e.y, i = e.z, a = Math.sqrt(n * n + r * r + i * i);
|
|
429
|
+
if (a === 0) return this.identity();
|
|
430
|
+
let o = t / 2, s = Math.sin(o) / a;
|
|
431
|
+
return this.w = Math.cos(o), this.x = s * n, this.y = s * r, this.z = s * i, this;
|
|
432
|
+
}
|
|
433
|
+
setToDifferenceQuaternion(e) {
|
|
434
|
+
let t = e.w, n = e.x, r = e.y, i = e.z, a = t * t + n * n + r * r + i * i, o = a === 0 ? 0 : 1 / a, s = t * o, c = -n * o, l = -r * o, u = -i * o, d = this.w, f = this.x, p = this.y, m = this.z;
|
|
435
|
+
return this.w = s * d - (c * f + l * p + u * m), this.x = s * f + d * c + (l * m - u * p), this.y = s * p + d * l + (u * f - c * m), this.z = s * m + d * u + (c * p - l * f), this;
|
|
436
|
+
}
|
|
437
|
+
rotateVec3(e, t = new r()) {
|
|
438
|
+
let n = this.w, i = this.x, a = this.y, o = this.z, s = e.x, c = e.y, l = e.z, u = 2 * (a * l - o * c), d = 2 * (o * s - i * l), f = 2 * (i * c - a * s);
|
|
439
|
+
return t.x = s + n * u + (a * f - o * d), t.y = c + n * d + (o * u - i * f), t.z = l + n * f + (i * d - a * u), t;
|
|
440
|
+
}
|
|
441
|
+
inverseRotateVec3(e, t = new r()) {
|
|
442
|
+
let n = this.w, i = this.x, a = this.y, o = this.z, s = e.x, c = e.y, l = e.z, u = 2 * (o * c - a * l), d = 2 * (i * l - o * s), f = 2 * (a * s - i * c);
|
|
443
|
+
return t.x = s + n * u - (a * f - o * d), t.y = c + n * d - (o * u - i * f), t.z = l + n * f - (i * d - a * u), t;
|
|
444
|
+
}
|
|
445
|
+
slerp(e, t) {
|
|
446
|
+
return this.slerpQuaternions(this, e, t);
|
|
447
|
+
}
|
|
448
|
+
slerpQuaternions(e, t, n) {
|
|
449
|
+
let r = e.w, i = e.x, a = e.y, o = e.z, s = t.w, l = t.x, u = t.y, d = t.z, f = r * s + i * l + a * u + o * d;
|
|
450
|
+
if (f < 0 && (s = -s, l = -l, u = -u, d = -d, f = -f), f > c) {
|
|
451
|
+
let e = 1 - n;
|
|
452
|
+
return this.w = e * r + n * s, this.x = e * i + n * l, this.y = e * a + n * u, this.z = e * o + n * d, this.normalize();
|
|
453
|
+
}
|
|
454
|
+
let p = Math.sqrt(1 - f * f), m = Math.atan2(p, f), h = 1 / p, g = Math.sin((1 - n) * m) * h, _ = Math.sin(n * m) * h;
|
|
455
|
+
return this.w = g * r + _ * s, this.x = g * i + _ * l, this.y = g * a + _ * u, this.z = g * o + _ * d, this;
|
|
456
|
+
}
|
|
457
|
+
addScaledAngularVelocity(e, t) {
|
|
458
|
+
let n = .5 * t, r = e.x * n, i = e.y * n, a = e.z * n, o = this.w, s = this.x, c = this.y, l = this.z;
|
|
459
|
+
return this.w = o - (r * s + i * c + a * l), this.x = s + o * r + (i * l - a * c), this.y = c + o * i + (a * s - r * l), this.z = l + o * a + (r * c - i * s), this;
|
|
460
|
+
}
|
|
461
|
+
setFromRotationMatrix(e) {
|
|
462
|
+
let t = e.elements, n = t[0], r = t[1], i = t[2], a = t[3], o = t[4], s = t[5], c = t[6], l = t[7], u = t[8], d = n + o + u;
|
|
463
|
+
if (d > 0) {
|
|
464
|
+
let e = 2 * Math.sqrt(d + 1);
|
|
465
|
+
this.w = .25 * e, this.x = (l - s) / e, this.y = (i - c) / e, this.z = (a - r) / e;
|
|
466
|
+
} else if (n > o && n > u) {
|
|
467
|
+
let e = 2 * Math.sqrt(1 + n - o - u);
|
|
468
|
+
this.w = (l - s) / e, this.x = .25 * e, this.y = (r + a) / e, this.z = (i + c) / e;
|
|
469
|
+
} else if (o > u) {
|
|
470
|
+
let e = 2 * Math.sqrt(1 + o - n - u);
|
|
471
|
+
this.w = (i - c) / e, this.x = (r + a) / e, this.y = .25 * e, this.z = (s + l) / e;
|
|
472
|
+
} else {
|
|
473
|
+
let e = 2 * Math.sqrt(1 + u - n - o);
|
|
474
|
+
this.w = (a - r) / e, this.x = (i + c) / e, this.y = (s + l) / e, this.z = .25 * e;
|
|
475
|
+
}
|
|
476
|
+
return this;
|
|
477
|
+
}
|
|
478
|
+
getAxisAngle(e = new r()) {
|
|
479
|
+
let t = this.w, n = this.x, i = this.y, a = this.z, o = Math.sqrt(n * n + i * i + a * a);
|
|
480
|
+
if (o === 0) return e.x = 1, e.y = 0, e.z = 0, 0;
|
|
481
|
+
let s = (t < 0 ? -1 : 1) / o;
|
|
482
|
+
return e.x = s * n, e.y = s * i, e.z = s * a, 2 * Math.atan2(o, Math.abs(t));
|
|
483
|
+
}
|
|
484
|
+
angleTo(e) {
|
|
485
|
+
let t = this.w, n = this.x, r = this.y, i = this.z, a = e.w, o = e.x, s = e.y, c = e.z, l = t * a + n * o + r * s + i * c, u = t * o - a * n - (r * c - i * s), d = t * s - a * r - (i * o - n * c), f = t * c - a * i - (n * s - r * o);
|
|
486
|
+
return 2 * Math.atan2(Math.sqrt(u * u + d * d + f * f), Math.abs(l));
|
|
487
|
+
}
|
|
488
|
+
setFromEulerXYZ(e, t, n) {
|
|
489
|
+
let r = Math.cos(e / 2), i = Math.sin(e / 2), a = Math.cos(t / 2), o = Math.sin(t / 2), s = Math.cos(n / 2), c = Math.sin(n / 2);
|
|
490
|
+
return this.w = r * a * s - i * o * c, this.x = i * a * s + r * o * c, this.y = r * o * s - i * a * c, this.z = r * a * c + i * o * s, this;
|
|
491
|
+
}
|
|
492
|
+
getEulerXYZ(e = new r()) {
|
|
493
|
+
let t = this.w, n = this.x, i = this.y, a = this.z, o = 1 - 2 * (i * i + a * a), s = 2 * (n * i - t * a), c = 2 * (n * a + t * i), l = 1 - 2 * (n * n + a * a), d = 2 * (i * a - t * n), f = 2 * (i * a + t * n), p = 1 - 2 * (n * n + i * i);
|
|
494
|
+
return e.y = Math.asin(Math.min(1, Math.max(-1, c))), Math.abs(c) < u ? (e.x = Math.atan2(-d, p), e.z = Math.atan2(-s, o)) : (e.x = Math.atan2(f, l), e.z = 0), e;
|
|
495
|
+
}
|
|
496
|
+
setFromUnitVectors(e, t) {
|
|
497
|
+
let n = e.x, r = e.y, i = e.z, a = t.x, o = t.y, s = t.z, c = 1 + (n * a + r * o + i * s);
|
|
498
|
+
return c < l ? (Math.abs(n) > Math.abs(i) ? (this.w = 0, this.x = -r, this.y = n, this.z = 0) : (this.w = 0, this.x = 0, this.y = -i, this.z = r), this.normalize()) : (this.w = c, this.x = r * s - i * o, this.y = i * a - n * s, this.z = n * o - r * a, this.normalize());
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
//#endregion
|
|
502
|
+
export { e as a, r as i, s as n, t as o, a as r, n as s, d as t };
|
package/dist/math.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { a as EPSILON, r as Mat3x3, n as Mat3x4, t as Quaternion, i as Vec3, o as approxEqual, s as clamp } from "./math-DrI-pge3.js";
|