aether-physics 0.0.0-stage → 0.2.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 +94 -2
- package/dist/index.js +88 -0
- package/dist/math-DrI-pge3.js +502 -0
- package/dist/math.js +1 -0
- package/dist/types/engine/index.d.ts +4 -0
- package/dist/types/engine/loop.d.ts +37 -0
- package/dist/types/engine/particle-world.d.ts +13 -0
- package/dist/types/engine/particle.d.ts +51 -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 +59 -5
|
@@ -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";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-timestep simulation clock with an accumulator.
|
|
3
|
+
*
|
|
4
|
+
* @see https://gafferongames.com/post/fix_your_timestep/
|
|
5
|
+
*/
|
|
6
|
+
export interface FrameResult {
|
|
7
|
+
/** Number of steps run. */
|
|
8
|
+
steps: number;
|
|
9
|
+
/** Interpolation factor in [0, 1) between the previous and current state. 1 while paused. */
|
|
10
|
+
alpha: number;
|
|
11
|
+
/** Whether accumulated time was discarded after reaching `maxStepsPerFrame`. */
|
|
12
|
+
droppedTime: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare class FixedStepLoop {
|
|
15
|
+
#private;
|
|
16
|
+
/** Simulation speed relative to real time. */
|
|
17
|
+
timeScale: number;
|
|
18
|
+
paused: boolean;
|
|
19
|
+
maxStepsPerFrame: number;
|
|
20
|
+
constructor(hz?: number);
|
|
21
|
+
/** Seconds per physics step. */
|
|
22
|
+
get dt(): number;
|
|
23
|
+
get hz(): number;
|
|
24
|
+
set hz(value: number);
|
|
25
|
+
/** Simulated time in seconds since the last reset. */
|
|
26
|
+
get simTime(): number;
|
|
27
|
+
/** Queues one step for the next `advance` call, regardless of `paused`. */
|
|
28
|
+
stepOnce(): void;
|
|
29
|
+
reset(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Advances the clock and runs `step` once per elapsed timestep.
|
|
32
|
+
*
|
|
33
|
+
* @param nowMs - Current timestamp in milliseconds.
|
|
34
|
+
* @param step - Called with the fixed timestep in seconds.
|
|
35
|
+
*/
|
|
36
|
+
advance(nowMs: number, step: (dt: number) => void): FrameResult;
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Particle } from "./particle.js";
|
|
2
|
+
/** A collection of particles stepped together. */
|
|
3
|
+
export declare class ParticleWorld {
|
|
4
|
+
/** Particles in this world, integrated in array order. Add and remove them directly. */
|
|
5
|
+
readonly particles: Particle[];
|
|
6
|
+
/**
|
|
7
|
+
* Integrates every particle by one step.
|
|
8
|
+
*
|
|
9
|
+
* @param dt Step length in seconds.
|
|
10
|
+
* @throws RangeError If `dt` is not positive and the world has particles.
|
|
11
|
+
*/
|
|
12
|
+
step(dt: number): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Vec3, type Vec3Like } from "../math/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* A point mass integrated with semi-implicit Euler.
|
|
4
|
+
*
|
|
5
|
+
* Mass is stored as its inverse, so `inverseMass = 0` represents an immovable particle.
|
|
6
|
+
* Vector fields are `readonly` references: change them in place, e.g.
|
|
7
|
+
* `particle.position.set(0, 1, 0)`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Particle {
|
|
10
|
+
/** Position in meters. */
|
|
11
|
+
readonly position: Vec3;
|
|
12
|
+
/** Velocity in meters per second. */
|
|
13
|
+
readonly velocity: Vec3;
|
|
14
|
+
/** Constant acceleration in m/s², independent of mass. Typically gravity. */
|
|
15
|
+
readonly acceleration: Vec3;
|
|
16
|
+
/** Sum of forces in newtons applied since the last `integrate`. */
|
|
17
|
+
readonly forceAccum: Vec3;
|
|
18
|
+
/** Fraction of velocity kept per second, in [0, 1]. `1` disables damping. */
|
|
19
|
+
damping: number;
|
|
20
|
+
/** Reciprocal of mass in 1/kg. `0` makes the particle immovable. */
|
|
21
|
+
inverseMass: number;
|
|
22
|
+
/** Mass in kilograms. `Infinity` when `inverseMass` is `0`. */
|
|
23
|
+
get mass(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Sets the mass.
|
|
26
|
+
*
|
|
27
|
+
* @param mass Mass in kilograms. `Infinity` makes the particle immovable.
|
|
28
|
+
* @throws RangeError If `mass` is not positive.
|
|
29
|
+
*/
|
|
30
|
+
setMass(mass: number): void;
|
|
31
|
+
/** Whether forces and integration can move this particle. */
|
|
32
|
+
hasFiniteMass(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Adds a force for the next `integrate`.
|
|
35
|
+
*
|
|
36
|
+
* @param force Force in newtons.
|
|
37
|
+
*/
|
|
38
|
+
addForce(force: Vec3Like): void;
|
|
39
|
+
/** Discards all accumulated forces. */
|
|
40
|
+
clearAccumulator(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Advances the particle by one step and clears the force accumulator.
|
|
43
|
+
*
|
|
44
|
+
* Velocity is updated first and the new velocity moves the position. A particle with
|
|
45
|
+
* `inverseMass = 0` does not move, whatever its velocity.
|
|
46
|
+
*
|
|
47
|
+
* @param dt Step length in seconds.
|
|
48
|
+
* @throws RangeError If `dt` is not positive.
|
|
49
|
+
*/
|
|
50
|
+
integrate(dt: number): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { FixedStepLoop, Particle, ParticleWorld } from './engine/index.js';
|
|
2
|
+
export type { FrameResult } from './engine/index.js';
|
|
3
|
+
export { EPSILON, approxEqual, clamp, Vec3, Mat3x3, Mat3x4, Quaternion } from './math/index.js';
|
|
4
|
+
export type { QuatLike, Vec3Like } from './math/index.js';
|