@ignifx/core 0.13.0 → 0.15.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/dist/agx-tone-mapping-Cgt844j6.js +53 -0
- package/dist/agx-tone-mapping-Cgt844j6.js.map +1 -0
- package/dist/auto-exposure-uzPn0beO.js +246 -0
- package/dist/auto-exposure-uzPn0beO.js.map +1 -0
- package/dist/bloom-hdr-CLtQj-oY.js +315 -0
- package/dist/bloom-hdr-CLtQj-oY.js.map +1 -0
- package/dist/contact-shadows-T523EXaP.js +84 -0
- package/dist/contact-shadows-T523EXaP.js.map +1 -0
- package/dist/{environment-C9AjYJgV.js → environment-DPi0_0SP.js} +19 -5
- package/dist/environment-DPi0_0SP.js.map +1 -0
- package/dist/gtao-_nr0b6-E.js +630 -0
- package/dist/gtao-_nr0b6-E.js.map +1 -0
- package/dist/hdr-output-BrUvpAsE.js +525 -0
- package/dist/hdr-output-BrUvpAsE.js.map +1 -0
- package/dist/{ignifx-error-Dq2qJMkZ.js → ignifx-error-oYdVnT1S.js} +16 -1
- package/dist/ignifx-error-oYdVnT1S.js.map +1 -0
- package/dist/index.d.ts +753 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1679 -183
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-DYwH0vLi.js → instanced-mesh-instance-NnODkvqK.js} +2 -2
- package/dist/{instanced-mesh-instance-DYwH0vLi.js.map → instanced-mesh-instance-NnODkvqK.js.map} +1 -1
- package/dist/mat4-D6exvAuO.js +949 -0
- package/dist/mat4-D6exvAuO.js.map +1 -0
- package/dist/material-CGk5mAah.js +204 -0
- package/dist/material-CGk5mAah.js.map +1 -0
- package/dist/{material-plugin-BOCB7Stt.js → material-plugin-BUlqLsap.js} +3 -204
- package/dist/material-plugin-BUlqLsap.js.map +1 -0
- package/dist/{post-effect-compiler-Dw6zW2cG.js → post-effect-compiler-CRek8VxQ.js} +2 -2
- package/dist/{post-effect-compiler-Dw6zW2cG.js.map → post-effect-compiler-CRek8VxQ.js.map} +1 -1
- package/dist/render-path-Be7WgN7r.js +166 -0
- package/dist/render-path-Be7WgN7r.js.map +1 -0
- package/dist/render-texture-C_TnaSz2.js +200 -0
- package/dist/render-texture-C_TnaSz2.js.map +1 -0
- package/dist/scene-color-passes-DlNr-qyZ.js +65 -0
- package/dist/scene-color-passes-DlNr-qyZ.js.map +1 -0
- package/dist/scene-inputs-BxGOsnIZ.js +318 -0
- package/dist/scene-inputs-BxGOsnIZ.js.map +1 -0
- package/dist/{shader-material-DRZmqA_S.js → shader-material-B6p66wB8.js} +18 -7
- package/dist/shader-material-B6p66wB8.js.map +1 -0
- package/dist/{shader-material-BxQn9FT4.js → shader-material-C0TAUr4t.js} +102 -4
- package/dist/shader-material-C0TAUr4t.js.map +1 -0
- package/dist/{shader-pragma-DrFm5f5m.js → shader-pragma-BKCoZTTA.js} +2 -2
- package/dist/{shader-pragma-DrFm5f5m.js.map → shader-pragma-BKCoZTTA.js.map} +1 -1
- package/dist/ssgi-Dm-maZrc.js +113 -0
- package/dist/ssgi-Dm-maZrc.js.map +1 -0
- package/dist/{surface-shader-BgZchRBe.js → surface-shader-BaK0kvBB.js} +5 -4
- package/dist/{surface-shader-BgZchRBe.js.map → surface-shader-BaK0kvBB.js.map} +1 -1
- package/dist/taa-BwBZLy11.js +480 -0
- package/dist/taa-BwBZLy11.js.map +1 -0
- package/dist/{vec3-T2PasQZv.js → vec3-D-0Y2mzE.js} +4 -948
- package/dist/vec3-D-0Y2mzE.js.map +1 -0
- package/package.json +1 -1
- package/dist/environment-C9AjYJgV.js.map +0 -1
- package/dist/ignifx-error-Dq2qJMkZ.js.map +0 -1
- package/dist/material-plugin-BOCB7Stt.js.map +0 -1
- package/dist/shader-material-BxQn9FT4.js.map +0 -1
- package/dist/shader-material-DRZmqA_S.js.map +0 -1
- package/dist/vec3-T2PasQZv.js.map +0 -1
|
@@ -1,950 +1,6 @@
|
|
|
1
|
-
import { n as EPSILON,
|
|
1
|
+
import { n as EPSILON, u as lerp } from "./math-utils-BcDnL-gi.js";
|
|
2
|
+
import { n as Mat4 } from "./mat4-D6exvAuO.js";
|
|
2
3
|
import { addToScene, cloneTransformNode, createBox, createCapsule, createCylinder, createGround, createMeshFromData, createPlane, createSphere, createTorus, createTransformNode, removeFromScene, setParent, setSubtreeVisible, updateMeshColors, updateMeshNormals, updateMeshPositions, updateMeshUvs } from "@babylonjs/lite";
|
|
3
|
-
//#region src/math/mat4.ts
|
|
4
|
-
/**
|
|
5
|
-
* Allocates the 16-element column-major storage a matrix owns, pre-filled with zeroes.
|
|
6
|
-
*
|
|
7
|
-
* @returns Fresh, zeroed storage.
|
|
8
|
-
*/
|
|
9
|
-
function allocateElements() {
|
|
10
|
-
return /* @__PURE__ */ new Float32Array(16);
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* The determinant of the upper-left 3×3 basis. Its sign says whether the matrix mirrors, which is
|
|
14
|
-
* how Babylon Lite decides the sign of the decomposed Y scale (`lib/math/mat4-decompose.js`).
|
|
15
|
-
*
|
|
16
|
-
* @param m - The matrix to measure.
|
|
17
|
-
* @returns The 3×3 determinant.
|
|
18
|
-
*/
|
|
19
|
-
function basisDeterminant(m) {
|
|
20
|
-
const m0 = m[0] ?? 0;
|
|
21
|
-
const m1 = m[1] ?? 0;
|
|
22
|
-
const m2 = m[2] ?? 0;
|
|
23
|
-
const m4 = m[4] ?? 0;
|
|
24
|
-
const m5 = m[5] ?? 0;
|
|
25
|
-
const m6 = m[6] ?? 0;
|
|
26
|
-
const m8 = m[8] ?? 0;
|
|
27
|
-
const m9 = m[9] ?? 0;
|
|
28
|
-
const m10 = m[10] ?? 0;
|
|
29
|
-
return m0 * (m5 * m10 - m6 * m9) + m1 * (m6 * m8 - m4 * m10) + m2 * (m4 * m9 - m5 * m8);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Writes the unit quaternion of an orthonormal basis into `out`. Arguments are named row-major
|
|
33
|
-
* (`b<row><column>`), matching Babylon Lite's `_quatFromRotationBasis`
|
|
34
|
-
* (`lib/math/quat-from-rotation-matrix.js`), which this reproduces branch for branch.
|
|
35
|
-
*
|
|
36
|
-
* Shared with the quaternion module; not part of the public API.
|
|
37
|
-
*
|
|
38
|
-
* @param b00 - Row 0, column 0.
|
|
39
|
-
* @param b01 - Row 0, column 1.
|
|
40
|
-
* @param b02 - Row 0, column 2.
|
|
41
|
-
* @param b10 - Row 1, column 0.
|
|
42
|
-
* @param b11 - Row 1, column 1.
|
|
43
|
-
* @param b12 - Row 1, column 2.
|
|
44
|
-
* @param b20 - Row 2, column 0.
|
|
45
|
-
* @param b21 - Row 2, column 1.
|
|
46
|
-
* @param b22 - Row 2, column 2.
|
|
47
|
-
* @param out - The quaternion to write.
|
|
48
|
-
*
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
function basisToQuatToRef(b00, b01, b02, b10, b11, b12, b20, b21, b22, out) {
|
|
52
|
-
const trace = b00 + b11 + b22;
|
|
53
|
-
if (trace > 0) {
|
|
54
|
-
const s = .5 / Math.sqrt(trace + 1);
|
|
55
|
-
out.set((b21 - b12) * s, (b02 - b20) * s, (b10 - b01) * s, .25 / s);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (b00 > b11 && b00 > b22) {
|
|
59
|
-
const s = 2 * Math.sqrt(1 + b00 - b11 - b22);
|
|
60
|
-
out.set(.25 * s, (b01 + b10) / s, (b02 + b20) / s, (b21 - b12) / s);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (b11 > b22) {
|
|
64
|
-
const s = 2 * Math.sqrt(1 + b11 - b00 - b22);
|
|
65
|
-
out.set((b01 + b10) / s, .25 * s, (b12 + b21) / s, (b02 - b20) / s);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const s = 2 * Math.sqrt(1 + b22 - b00 - b11);
|
|
69
|
-
out.set((b02 + b20) / s, (b12 + b21) / s, .25 * s, (b10 - b01) / s);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* A 4×4 transformation matrix stored column-major in a `Float32Array`, byte-compatible with WGSL's
|
|
73
|
-
* `mat4x4<f32>` and with Babylon Lite's `Mat4` (translation in slots 12/13/14).
|
|
74
|
-
*
|
|
75
|
-
* ignifx is left-handed, Y up, +Z forward (ADR-0011), so the projection helpers are the `LH`
|
|
76
|
-
* family and they use Lite's **reverse depth** convention: the near plane maps to 1 and the far
|
|
77
|
-
* plane to 0.
|
|
78
|
-
*
|
|
79
|
-
* Instance methods mutate the matrix and return `this`; `ToRef` statics write into their `out`
|
|
80
|
-
* matrix and allocate nothing, and are safe when `out` aliases an input. The remaining statics
|
|
81
|
-
* allocate a fresh matrix and say so.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* const world = new Mat4();
|
|
86
|
-
* Mat4.composeToRef(position, rotation, scale, world);
|
|
87
|
-
*
|
|
88
|
-
* const inverse = new Mat4();
|
|
89
|
-
* if (Mat4.invertToRef(world, inverse)) {
|
|
90
|
-
* Mat4.transformPointToRef(inverse, worldPoint, localPoint);
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @public
|
|
95
|
-
*/
|
|
96
|
-
var Mat4 = class Mat4 {
|
|
97
|
-
/**
|
|
98
|
-
* The 16 elements, column-major (`elements[column * 4 + row]`). This is the object to hand to
|
|
99
|
-
* anything that wants a {@link Mat4Like} — including Babylon Lite — and the buffer to upload to
|
|
100
|
-
* the GPU. It is never reallocated, so a reference to it stays valid for the matrix's lifetime.
|
|
101
|
-
*/
|
|
102
|
-
elements;
|
|
103
|
-
/**
|
|
104
|
-
* Creates an identity matrix.
|
|
105
|
-
*/
|
|
106
|
-
constructor() {
|
|
107
|
-
const e = allocateElements();
|
|
108
|
-
e[0] = 1;
|
|
109
|
-
e[5] = 1;
|
|
110
|
-
e[10] = 1;
|
|
111
|
-
e[15] = 1;
|
|
112
|
-
this.elements = e;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Resets this matrix to the identity.
|
|
116
|
-
*
|
|
117
|
-
* @returns This matrix.
|
|
118
|
-
*/
|
|
119
|
-
identity() {
|
|
120
|
-
const e = this.elements;
|
|
121
|
-
e[0] = 1;
|
|
122
|
-
e[1] = 0;
|
|
123
|
-
e[2] = 0;
|
|
124
|
-
e[3] = 0;
|
|
125
|
-
e[4] = 0;
|
|
126
|
-
e[5] = 1;
|
|
127
|
-
e[6] = 0;
|
|
128
|
-
e[7] = 0;
|
|
129
|
-
e[8] = 0;
|
|
130
|
-
e[9] = 0;
|
|
131
|
-
e[10] = 1;
|
|
132
|
-
e[11] = 0;
|
|
133
|
-
e[12] = 0;
|
|
134
|
-
e[13] = 0;
|
|
135
|
-
e[14] = 0;
|
|
136
|
-
e[15] = 1;
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Copies every element from another matrix.
|
|
141
|
-
*
|
|
142
|
-
* @param m - The matrix to read.
|
|
143
|
-
* @returns This matrix.
|
|
144
|
-
*/
|
|
145
|
-
copyFrom(m) {
|
|
146
|
-
const e = this.elements;
|
|
147
|
-
for (let i = 0; i < 16; i++) e[i] = m[i] ?? 0;
|
|
148
|
-
return this;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Copies this matrix into a new one.
|
|
152
|
-
*
|
|
153
|
-
* @returns A new matrix. **Allocates.**
|
|
154
|
-
*/
|
|
155
|
-
clone() {
|
|
156
|
-
return new Mat4().copyFrom(this.elements);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Post-multiplies this matrix by another (`this = this * m`), so `m`'s transform is applied first
|
|
160
|
-
* when the product acts on a column vector.
|
|
161
|
-
*
|
|
162
|
-
* @param m - The right-hand matrix.
|
|
163
|
-
* @returns This matrix.
|
|
164
|
-
*/
|
|
165
|
-
multiply(m) {
|
|
166
|
-
Mat4.multiplyToRef(this.elements, m, this);
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Inverts this matrix in place.
|
|
171
|
-
*
|
|
172
|
-
* @returns `true` on success. When the matrix is singular this returns `false` and leaves the
|
|
173
|
-
* matrix untouched.
|
|
174
|
-
*/
|
|
175
|
-
invert() {
|
|
176
|
-
return Mat4.invertToRef(this.elements, this);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Transposes this matrix in place, swapping rows and columns.
|
|
180
|
-
*
|
|
181
|
-
* @returns This matrix.
|
|
182
|
-
*/
|
|
183
|
-
transpose() {
|
|
184
|
-
Mat4.transposeToRef(this.elements, this);
|
|
185
|
-
return this;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* The full 4×4 determinant of this matrix.
|
|
189
|
-
*
|
|
190
|
-
* @returns The determinant; zero means the matrix cannot be inverted.
|
|
191
|
-
*/
|
|
192
|
-
determinant() {
|
|
193
|
-
return Mat4.determinant(this.elements);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Compares this matrix with another element by element, with a tolerance.
|
|
197
|
-
*
|
|
198
|
-
* @param m - The matrix to compare against.
|
|
199
|
-
* @param epsilon - The largest per-element difference still considered equal.
|
|
200
|
-
* @returns `true` when every element matches within `epsilon`.
|
|
201
|
-
*/
|
|
202
|
-
equalsWithEpsilon(m, epsilon = EPSILON) {
|
|
203
|
-
return Mat4.equalsWithEpsilon(this.elements, m, epsilon);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Creates an identity matrix.
|
|
207
|
-
*
|
|
208
|
-
* @returns A new identity matrix. **Allocates.**
|
|
209
|
-
*/
|
|
210
|
-
static identity() {
|
|
211
|
-
return new Mat4();
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Creates a matrix holding a copy of another matrix's elements.
|
|
215
|
-
*
|
|
216
|
-
* @param m - The matrix to copy.
|
|
217
|
-
* @returns A new matrix. **Allocates.**
|
|
218
|
-
*/
|
|
219
|
-
static from(m) {
|
|
220
|
-
return new Mat4().copyFrom(m);
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Builds a translation-rotation-scale matrix, the same composition order Babylon Lite's
|
|
224
|
-
* `mat4Compose` uses (`translation * rotation * scale`).
|
|
225
|
-
*
|
|
226
|
-
* @param position - The translation, in metres.
|
|
227
|
-
* @param rotation - The rotation; assumed to be a unit quaternion.
|
|
228
|
-
* @param scale - The per-axis scale.
|
|
229
|
-
* @returns A new matrix. **Allocates.**
|
|
230
|
-
*/
|
|
231
|
-
static compose(position, rotation, scale) {
|
|
232
|
-
return Mat4.composeToRef(position, rotation, scale, new Mat4());
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Writes a translation-rotation-scale matrix into `out`.
|
|
236
|
-
*
|
|
237
|
-
* @param position - The translation, in metres.
|
|
238
|
-
* @param rotation - The rotation; assumed to be a unit quaternion.
|
|
239
|
-
* @param scale - The per-axis scale.
|
|
240
|
-
* @param out - The matrix to write.
|
|
241
|
-
* @returns `out`.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```ts
|
|
245
|
-
* Mat4.composeToRef(transform.localPosition, transform.localRotation, transform.localScale, local);
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
static composeToRef(position, rotation, scale, out) {
|
|
249
|
-
const qx = rotation.x;
|
|
250
|
-
const qy = rotation.y;
|
|
251
|
-
const qz = rotation.z;
|
|
252
|
-
const qw = rotation.w;
|
|
253
|
-
const sx = scale.x;
|
|
254
|
-
const sy = scale.y;
|
|
255
|
-
const sz = scale.z;
|
|
256
|
-
const xx = qx * qx;
|
|
257
|
-
const yy = qy * qy;
|
|
258
|
-
const zz = qz * qz;
|
|
259
|
-
const xy = qx * qy;
|
|
260
|
-
const xz = qx * qz;
|
|
261
|
-
const yz = qy * qz;
|
|
262
|
-
const wx = qw * qx;
|
|
263
|
-
const wy = qw * qy;
|
|
264
|
-
const wz = qw * qz;
|
|
265
|
-
const e = out.elements;
|
|
266
|
-
e[0] = (1 - 2 * (yy + zz)) * sx;
|
|
267
|
-
e[1] = 2 * (xy + wz) * sx;
|
|
268
|
-
e[2] = 2 * (xz - wy) * sx;
|
|
269
|
-
e[3] = 0;
|
|
270
|
-
e[4] = 2 * (xy - wz) * sy;
|
|
271
|
-
e[5] = (1 - 2 * (xx + zz)) * sy;
|
|
272
|
-
e[6] = 2 * (yz + wx) * sy;
|
|
273
|
-
e[7] = 0;
|
|
274
|
-
e[8] = 2 * (xz + wy) * sz;
|
|
275
|
-
e[9] = 2 * (yz - wx) * sz;
|
|
276
|
-
e[10] = (1 - 2 * (xx + yy)) * sz;
|
|
277
|
-
e[11] = 0;
|
|
278
|
-
e[12] = position.x;
|
|
279
|
-
e[13] = position.y;
|
|
280
|
-
e[14] = position.z;
|
|
281
|
-
e[15] = 1;
|
|
282
|
-
return out;
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Splits an affine transformation-rotation-scale matrix back into its parts, using Babylon Lite's
|
|
286
|
-
* convention (`lib/math/mat4-decompose.js`): scales are the lengths of the basis columns, and a
|
|
287
|
-
* mirrored matrix (negative basis determinant) reports a **negative Y scale** rather than
|
|
288
|
-
* silently dropping the reflection. Shear is not detected.
|
|
289
|
-
*
|
|
290
|
-
* @param m - The matrix to split.
|
|
291
|
-
* @param outPosition - Receives the translation.
|
|
292
|
-
* @param outRotation - Receives the rotation as a unit quaternion.
|
|
293
|
-
* @param outScale - Receives the per-axis scale.
|
|
294
|
-
* @returns `true` on success; `false` when a basis column has (near) zero length, in which case
|
|
295
|
-
* the outputs are left untouched.
|
|
296
|
-
*
|
|
297
|
-
* @example
|
|
298
|
-
* ```ts
|
|
299
|
-
* Mat4.decomposeToRef(node.worldMatrix, position, rotation, scale);
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
static decomposeToRef(m, outPosition, outRotation, outScale) {
|
|
303
|
-
const m0 = m[0] ?? 0;
|
|
304
|
-
const m1 = m[1] ?? 0;
|
|
305
|
-
const m2 = m[2] ?? 0;
|
|
306
|
-
const m4 = m[4] ?? 0;
|
|
307
|
-
const m5 = m[5] ?? 0;
|
|
308
|
-
const m6 = m[6] ?? 0;
|
|
309
|
-
const m8 = m[8] ?? 0;
|
|
310
|
-
const m9 = m[9] ?? 0;
|
|
311
|
-
const m10 = m[10] ?? 0;
|
|
312
|
-
const sx = Math.hypot(m0, m1, m2);
|
|
313
|
-
const syAbs = Math.hypot(m4, m5, m6);
|
|
314
|
-
const sz = Math.hypot(m8, m9, m10);
|
|
315
|
-
if (sx <= 1e-8 || syAbs <= 1e-8 || sz <= 1e-8) return false;
|
|
316
|
-
const sy = basisDeterminant(m) < 0 ? -syAbs : syAbs;
|
|
317
|
-
const invSx = 1 / sx;
|
|
318
|
-
const invSy = 1 / sy;
|
|
319
|
-
const invSz = 1 / sz;
|
|
320
|
-
const tx = m[12] ?? 0;
|
|
321
|
-
const ty = m[13] ?? 0;
|
|
322
|
-
const tz = m[14] ?? 0;
|
|
323
|
-
basisToQuatToRef(m0 * invSx, m4 * invSy, m8 * invSz, m1 * invSx, m5 * invSy, m9 * invSz, m2 * invSx, m6 * invSy, m10 * invSz, outRotation);
|
|
324
|
-
const qx = outRotation.x;
|
|
325
|
-
const qy = outRotation.y;
|
|
326
|
-
const qz = outRotation.z;
|
|
327
|
-
const qw = outRotation.w;
|
|
328
|
-
const invLength = 1 / Math.hypot(qx, qy, qz, qw);
|
|
329
|
-
outRotation.set(qx * invLength, qy * invLength, qz * invLength, qw * invLength);
|
|
330
|
-
outPosition.set(tx, ty, tz);
|
|
331
|
-
outScale.set(sx, sy, sz);
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Multiplies two matrices.
|
|
336
|
-
*
|
|
337
|
-
* @param a - The left-hand matrix.
|
|
338
|
-
* @param b - The right-hand matrix.
|
|
339
|
-
* @returns A new matrix holding `a * b`. **Allocates.**
|
|
340
|
-
*/
|
|
341
|
-
static multiply(a, b) {
|
|
342
|
-
return Mat4.multiplyToRef(a, b, new Mat4());
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Writes `a * b` into `out`. Acting on a column vector, `b` is applied first.
|
|
346
|
-
*
|
|
347
|
-
* @param a - The left-hand matrix.
|
|
348
|
-
* @param b - The right-hand matrix.
|
|
349
|
-
* @param out - The matrix to write; may alias `a` or `b`.
|
|
350
|
-
* @returns `out`.
|
|
351
|
-
*/
|
|
352
|
-
static multiplyToRef(a, b, out) {
|
|
353
|
-
const a0 = a[0] ?? 0;
|
|
354
|
-
const a1 = a[1] ?? 0;
|
|
355
|
-
const a2 = a[2] ?? 0;
|
|
356
|
-
const a3 = a[3] ?? 0;
|
|
357
|
-
const a4 = a[4] ?? 0;
|
|
358
|
-
const a5 = a[5] ?? 0;
|
|
359
|
-
const a6 = a[6] ?? 0;
|
|
360
|
-
const a7 = a[7] ?? 0;
|
|
361
|
-
const a8 = a[8] ?? 0;
|
|
362
|
-
const a9 = a[9] ?? 0;
|
|
363
|
-
const a10 = a[10] ?? 0;
|
|
364
|
-
const a11 = a[11] ?? 0;
|
|
365
|
-
const a12 = a[12] ?? 0;
|
|
366
|
-
const a13 = a[13] ?? 0;
|
|
367
|
-
const a14 = a[14] ?? 0;
|
|
368
|
-
const a15 = a[15] ?? 0;
|
|
369
|
-
const b0 = b[0] ?? 0;
|
|
370
|
-
const b1 = b[1] ?? 0;
|
|
371
|
-
const b2 = b[2] ?? 0;
|
|
372
|
-
const b3 = b[3] ?? 0;
|
|
373
|
-
const b4 = b[4] ?? 0;
|
|
374
|
-
const b5 = b[5] ?? 0;
|
|
375
|
-
const b6 = b[6] ?? 0;
|
|
376
|
-
const b7 = b[7] ?? 0;
|
|
377
|
-
const b8 = b[8] ?? 0;
|
|
378
|
-
const b9 = b[9] ?? 0;
|
|
379
|
-
const b10 = b[10] ?? 0;
|
|
380
|
-
const b11 = b[11] ?? 0;
|
|
381
|
-
const b12 = b[12] ?? 0;
|
|
382
|
-
const b13 = b[13] ?? 0;
|
|
383
|
-
const b14 = b[14] ?? 0;
|
|
384
|
-
const b15 = b[15] ?? 0;
|
|
385
|
-
const e = out.elements;
|
|
386
|
-
e[0] = a0 * b0 + a4 * b1 + a8 * b2 + a12 * b3;
|
|
387
|
-
e[1] = a1 * b0 + a5 * b1 + a9 * b2 + a13 * b3;
|
|
388
|
-
e[2] = a2 * b0 + a6 * b1 + a10 * b2 + a14 * b3;
|
|
389
|
-
e[3] = a3 * b0 + a7 * b1 + a11 * b2 + a15 * b3;
|
|
390
|
-
e[4] = a0 * b4 + a4 * b5 + a8 * b6 + a12 * b7;
|
|
391
|
-
e[5] = a1 * b4 + a5 * b5 + a9 * b6 + a13 * b7;
|
|
392
|
-
e[6] = a2 * b4 + a6 * b5 + a10 * b6 + a14 * b7;
|
|
393
|
-
e[7] = a3 * b4 + a7 * b5 + a11 * b6 + a15 * b7;
|
|
394
|
-
e[8] = a0 * b8 + a4 * b9 + a8 * b10 + a12 * b11;
|
|
395
|
-
e[9] = a1 * b8 + a5 * b9 + a9 * b10 + a13 * b11;
|
|
396
|
-
e[10] = a2 * b8 + a6 * b9 + a10 * b10 + a14 * b11;
|
|
397
|
-
e[11] = a3 * b8 + a7 * b9 + a11 * b10 + a15 * b11;
|
|
398
|
-
e[12] = a0 * b12 + a4 * b13 + a8 * b14 + a12 * b15;
|
|
399
|
-
e[13] = a1 * b12 + a5 * b13 + a9 * b14 + a13 * b15;
|
|
400
|
-
e[14] = a2 * b12 + a6 * b13 + a10 * b14 + a14 * b15;
|
|
401
|
-
e[15] = a3 * b12 + a7 * b13 + a11 * b14 + a15 * b15;
|
|
402
|
-
return out;
|
|
403
|
-
}
|
|
404
|
-
/**
|
|
405
|
-
* Writes the inverse of `m` into `out`.
|
|
406
|
-
*
|
|
407
|
-
* @param m - The matrix to invert.
|
|
408
|
-
* @param out - The matrix to write; may alias `m`. Left untouched when the inverse does not exist.
|
|
409
|
-
* @returns `true` on success, `false` when `m` is singular. Returning a status rather than `null`
|
|
410
|
-
* keeps the call allocation-free (coding standards §7).
|
|
411
|
-
*
|
|
412
|
-
* @example
|
|
413
|
-
* ```ts
|
|
414
|
-
* if (!Mat4.invertToRef(world, worldToLocal)) {
|
|
415
|
-
* // degenerate scale — skip this entity
|
|
416
|
-
* }
|
|
417
|
-
* ```
|
|
418
|
-
*/
|
|
419
|
-
static invertToRef(m, out) {
|
|
420
|
-
const a00 = m[0] ?? 0;
|
|
421
|
-
const a01 = m[1] ?? 0;
|
|
422
|
-
const a02 = m[2] ?? 0;
|
|
423
|
-
const a03 = m[3] ?? 0;
|
|
424
|
-
const a10 = m[4] ?? 0;
|
|
425
|
-
const a11 = m[5] ?? 0;
|
|
426
|
-
const a12 = m[6] ?? 0;
|
|
427
|
-
const a13 = m[7] ?? 0;
|
|
428
|
-
const a20 = m[8] ?? 0;
|
|
429
|
-
const a21 = m[9] ?? 0;
|
|
430
|
-
const a22 = m[10] ?? 0;
|
|
431
|
-
const a23 = m[11] ?? 0;
|
|
432
|
-
const a30 = m[12] ?? 0;
|
|
433
|
-
const a31 = m[13] ?? 0;
|
|
434
|
-
const a32 = m[14] ?? 0;
|
|
435
|
-
const a33 = m[15] ?? 0;
|
|
436
|
-
const b00 = a00 * a11 - a01 * a10;
|
|
437
|
-
const b01 = a00 * a12 - a02 * a10;
|
|
438
|
-
const b02 = a00 * a13 - a03 * a10;
|
|
439
|
-
const b03 = a01 * a12 - a02 * a11;
|
|
440
|
-
const b04 = a01 * a13 - a03 * a11;
|
|
441
|
-
const b05 = a02 * a13 - a03 * a12;
|
|
442
|
-
const b06 = a20 * a31 - a21 * a30;
|
|
443
|
-
const b07 = a20 * a32 - a22 * a30;
|
|
444
|
-
const b08 = a20 * a33 - a23 * a30;
|
|
445
|
-
const b09 = a21 * a32 - a22 * a31;
|
|
446
|
-
const b10 = a21 * a33 - a23 * a31;
|
|
447
|
-
const b11 = a22 * a33 - a23 * a32;
|
|
448
|
-
const determinant = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
449
|
-
if (Math.abs(determinant) < 1e-10) return false;
|
|
450
|
-
const inv = 1 / determinant;
|
|
451
|
-
const e = out.elements;
|
|
452
|
-
e[0] = (a11 * b11 - a12 * b10 + a13 * b09) * inv;
|
|
453
|
-
e[1] = (a02 * b10 - a01 * b11 - a03 * b09) * inv;
|
|
454
|
-
e[2] = (a31 * b05 - a32 * b04 + a33 * b03) * inv;
|
|
455
|
-
e[3] = (a22 * b04 - a21 * b05 - a23 * b03) * inv;
|
|
456
|
-
e[4] = (a12 * b08 - a10 * b11 - a13 * b07) * inv;
|
|
457
|
-
e[5] = (a00 * b11 - a02 * b08 + a03 * b07) * inv;
|
|
458
|
-
e[6] = (a32 * b02 - a30 * b05 - a33 * b01) * inv;
|
|
459
|
-
e[7] = (a20 * b05 - a22 * b02 + a23 * b01) * inv;
|
|
460
|
-
e[8] = (a10 * b10 - a11 * b08 + a13 * b06) * inv;
|
|
461
|
-
e[9] = (a01 * b08 - a00 * b10 - a03 * b06) * inv;
|
|
462
|
-
e[10] = (a30 * b04 - a31 * b02 + a33 * b00) * inv;
|
|
463
|
-
e[11] = (a21 * b02 - a20 * b04 - a23 * b00) * inv;
|
|
464
|
-
e[12] = (a11 * b07 - a10 * b09 - a12 * b06) * inv;
|
|
465
|
-
e[13] = (a00 * b09 - a01 * b07 + a02 * b06) * inv;
|
|
466
|
-
e[14] = (a31 * b01 - a30 * b03 - a32 * b00) * inv;
|
|
467
|
-
e[15] = (a20 * b03 - a21 * b01 + a22 * b00) * inv;
|
|
468
|
-
return true;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Writes the transpose of `m` into `out`.
|
|
472
|
-
*
|
|
473
|
-
* @param m - The matrix to transpose.
|
|
474
|
-
* @param out - The matrix to write; may alias `m`.
|
|
475
|
-
* @returns `out`.
|
|
476
|
-
*/
|
|
477
|
-
static transposeToRef(m, out) {
|
|
478
|
-
const m0 = m[0] ?? 0;
|
|
479
|
-
const m1 = m[1] ?? 0;
|
|
480
|
-
const m2 = m[2] ?? 0;
|
|
481
|
-
const m3 = m[3] ?? 0;
|
|
482
|
-
const m4 = m[4] ?? 0;
|
|
483
|
-
const m5 = m[5] ?? 0;
|
|
484
|
-
const m6 = m[6] ?? 0;
|
|
485
|
-
const m7 = m[7] ?? 0;
|
|
486
|
-
const m8 = m[8] ?? 0;
|
|
487
|
-
const m9 = m[9] ?? 0;
|
|
488
|
-
const m10 = m[10] ?? 0;
|
|
489
|
-
const m11 = m[11] ?? 0;
|
|
490
|
-
const m12 = m[12] ?? 0;
|
|
491
|
-
const m13 = m[13] ?? 0;
|
|
492
|
-
const m14 = m[14] ?? 0;
|
|
493
|
-
const m15 = m[15] ?? 0;
|
|
494
|
-
const e = out.elements;
|
|
495
|
-
e[0] = m0;
|
|
496
|
-
e[1] = m4;
|
|
497
|
-
e[2] = m8;
|
|
498
|
-
e[3] = m12;
|
|
499
|
-
e[4] = m1;
|
|
500
|
-
e[5] = m5;
|
|
501
|
-
e[6] = m9;
|
|
502
|
-
e[7] = m13;
|
|
503
|
-
e[8] = m2;
|
|
504
|
-
e[9] = m6;
|
|
505
|
-
e[10] = m10;
|
|
506
|
-
e[11] = m14;
|
|
507
|
-
e[12] = m3;
|
|
508
|
-
e[13] = m7;
|
|
509
|
-
e[14] = m11;
|
|
510
|
-
e[15] = m15;
|
|
511
|
-
return out;
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* The full 4×4 determinant.
|
|
515
|
-
*
|
|
516
|
-
* @param m - The matrix to measure.
|
|
517
|
-
* @returns The determinant; zero means the matrix cannot be inverted.
|
|
518
|
-
*/
|
|
519
|
-
static determinant(m) {
|
|
520
|
-
const a00 = m[0] ?? 0;
|
|
521
|
-
const a01 = m[1] ?? 0;
|
|
522
|
-
const a02 = m[2] ?? 0;
|
|
523
|
-
const a03 = m[3] ?? 0;
|
|
524
|
-
const a10 = m[4] ?? 0;
|
|
525
|
-
const a11 = m[5] ?? 0;
|
|
526
|
-
const a12 = m[6] ?? 0;
|
|
527
|
-
const a13 = m[7] ?? 0;
|
|
528
|
-
const a20 = m[8] ?? 0;
|
|
529
|
-
const a21 = m[9] ?? 0;
|
|
530
|
-
const a22 = m[10] ?? 0;
|
|
531
|
-
const a23 = m[11] ?? 0;
|
|
532
|
-
const a30 = m[12] ?? 0;
|
|
533
|
-
const a31 = m[13] ?? 0;
|
|
534
|
-
const a32 = m[14] ?? 0;
|
|
535
|
-
const a33 = m[15] ?? 0;
|
|
536
|
-
const b00 = a00 * a11 - a01 * a10;
|
|
537
|
-
const b01 = a00 * a12 - a02 * a10;
|
|
538
|
-
const b02 = a00 * a13 - a03 * a10;
|
|
539
|
-
const b03 = a01 * a12 - a02 * a11;
|
|
540
|
-
const b04 = a01 * a13 - a03 * a11;
|
|
541
|
-
const b05 = a02 * a13 - a03 * a12;
|
|
542
|
-
const b06 = a20 * a31 - a21 * a30;
|
|
543
|
-
const b07 = a20 * a32 - a22 * a30;
|
|
544
|
-
const b08 = a20 * a33 - a23 * a30;
|
|
545
|
-
const b09 = a21 * a32 - a22 * a31;
|
|
546
|
-
const b10 = a21 * a33 - a23 * a31;
|
|
547
|
-
return b00 * (a22 * a33 - a23 * a32) - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Builds a pure translation matrix.
|
|
551
|
-
*
|
|
552
|
-
* @param x - Translation along X, in metres.
|
|
553
|
-
* @param y - Translation along Y, in metres.
|
|
554
|
-
* @param z - Translation along Z, in metres.
|
|
555
|
-
* @returns A new matrix. **Allocates.**
|
|
556
|
-
*/
|
|
557
|
-
static translation(x, y, z) {
|
|
558
|
-
return Mat4.translationToRef(x, y, z, new Mat4());
|
|
559
|
-
}
|
|
560
|
-
/**
|
|
561
|
-
* Writes a pure translation matrix into `out`.
|
|
562
|
-
*
|
|
563
|
-
* @param x - Translation along X, in metres.
|
|
564
|
-
* @param y - Translation along Y, in metres.
|
|
565
|
-
* @param z - Translation along Z, in metres.
|
|
566
|
-
* @param out - The matrix to write.
|
|
567
|
-
* @returns `out`.
|
|
568
|
-
*/
|
|
569
|
-
static translationToRef(x, y, z, out) {
|
|
570
|
-
const e = out.identity().elements;
|
|
571
|
-
e[12] = x;
|
|
572
|
-
e[13] = y;
|
|
573
|
-
e[14] = z;
|
|
574
|
-
return out;
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Builds a pure scaling matrix.
|
|
578
|
-
*
|
|
579
|
-
* @param x - Scale along X.
|
|
580
|
-
* @param y - Scale along Y.
|
|
581
|
-
* @param z - Scale along Z.
|
|
582
|
-
* @returns A new matrix. **Allocates.**
|
|
583
|
-
*/
|
|
584
|
-
static scaling(x, y, z) {
|
|
585
|
-
return Mat4.scalingToRef(x, y, z, new Mat4());
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* Writes a pure scaling matrix into `out`.
|
|
589
|
-
*
|
|
590
|
-
* @param x - Scale along X.
|
|
591
|
-
* @param y - Scale along Y.
|
|
592
|
-
* @param z - Scale along Z.
|
|
593
|
-
* @param out - The matrix to write.
|
|
594
|
-
* @returns `out`.
|
|
595
|
-
*/
|
|
596
|
-
static scalingToRef(x, y, z, out) {
|
|
597
|
-
const e = out.identity().elements;
|
|
598
|
-
e[0] = x;
|
|
599
|
-
e[5] = y;
|
|
600
|
-
e[10] = z;
|
|
601
|
-
return out;
|
|
602
|
-
}
|
|
603
|
-
/**
|
|
604
|
-
* Builds a pure rotation matrix from a quaternion.
|
|
605
|
-
*
|
|
606
|
-
* @param q - The rotation; assumed to be a unit quaternion.
|
|
607
|
-
* @returns A new matrix. **Allocates.**
|
|
608
|
-
*/
|
|
609
|
-
static fromQuat(q) {
|
|
610
|
-
return Mat4.fromQuatToRef(q, new Mat4());
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Writes a pure rotation matrix into `out`.
|
|
614
|
-
*
|
|
615
|
-
* @param q - The rotation; assumed to be a unit quaternion.
|
|
616
|
-
* @param out - The matrix to write.
|
|
617
|
-
* @returns `out`.
|
|
618
|
-
*/
|
|
619
|
-
static fromQuatToRef(q, out) {
|
|
620
|
-
return Mat4.composeToRef(ZERO_TRANSLATION, q, UNIT_SCALE, out);
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Builds a left-handed view matrix that places the camera at `eye` looking at `target`.
|
|
624
|
-
*
|
|
625
|
-
* @param eye - The camera position, in metres.
|
|
626
|
-
* @param target - The point to look at, in metres.
|
|
627
|
-
* @param up - The camera's up direction.
|
|
628
|
-
* @returns A new matrix. **Allocates.**
|
|
629
|
-
*/
|
|
630
|
-
static lookAtLH(eye, target, up) {
|
|
631
|
-
return Mat4.lookAtLHToRef(eye, target, up, new Mat4());
|
|
632
|
-
}
|
|
633
|
-
/**
|
|
634
|
-
* Writes a left-handed view matrix into `out`. Reproduces Babylon Lite's `mat4LookAtLHToRef`,
|
|
635
|
-
* including its degenerate-input behaviour: when `eye` and `target` coincide, or when `up` is
|
|
636
|
-
* parallel to the view direction, `out` becomes the identity.
|
|
637
|
-
*
|
|
638
|
-
* @param eye - The camera position, in metres.
|
|
639
|
-
* @param target - The point to look at, in metres.
|
|
640
|
-
* @param up - The camera's up direction.
|
|
641
|
-
* @param out - The matrix to write.
|
|
642
|
-
* @returns `out`.
|
|
643
|
-
*/
|
|
644
|
-
static lookAtLHToRef(eye, target, up, out) {
|
|
645
|
-
const ex = eye.x;
|
|
646
|
-
const ey = eye.y;
|
|
647
|
-
const ez = eye.z;
|
|
648
|
-
let zx = target.x - ex;
|
|
649
|
-
let zy = target.y - ey;
|
|
650
|
-
let zz = target.z - ez;
|
|
651
|
-
const zLength = Math.hypot(zx, zy, zz);
|
|
652
|
-
if (zLength < 1e-10) return out.identity();
|
|
653
|
-
const invZ = 1 / zLength;
|
|
654
|
-
zx *= invZ;
|
|
655
|
-
zy *= invZ;
|
|
656
|
-
zz *= invZ;
|
|
657
|
-
let xx = up.y * zz - up.z * zy;
|
|
658
|
-
let xy = up.z * zx - up.x * zz;
|
|
659
|
-
let xz = up.x * zy - up.y * zx;
|
|
660
|
-
const xLength = Math.hypot(xx, xy, xz);
|
|
661
|
-
if (xLength < 1e-10) return out.identity();
|
|
662
|
-
const invX = 1 / xLength;
|
|
663
|
-
xx *= invX;
|
|
664
|
-
xy *= invX;
|
|
665
|
-
xz *= invX;
|
|
666
|
-
const yx = zy * xz - zz * xy;
|
|
667
|
-
const yy = zz * xx - zx * xz;
|
|
668
|
-
const yz = zx * xy - zy * xx;
|
|
669
|
-
const e = out.elements;
|
|
670
|
-
e[0] = xx;
|
|
671
|
-
e[1] = yx;
|
|
672
|
-
e[2] = zx;
|
|
673
|
-
e[3] = 0;
|
|
674
|
-
e[4] = xy;
|
|
675
|
-
e[5] = yy;
|
|
676
|
-
e[6] = zy;
|
|
677
|
-
e[7] = 0;
|
|
678
|
-
e[8] = xz;
|
|
679
|
-
e[9] = yz;
|
|
680
|
-
e[10] = zz;
|
|
681
|
-
e[11] = 0;
|
|
682
|
-
e[12] = -(xx * ex + xy * ey + xz * ez);
|
|
683
|
-
e[13] = -(yx * ex + yy * ey + yz * ez);
|
|
684
|
-
e[14] = -(zx * ex + zy * ey + zz * ez);
|
|
685
|
-
e[15] = 1;
|
|
686
|
-
return out;
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Builds a left-handed perspective projection.
|
|
690
|
-
*
|
|
691
|
-
* @param fovDegrees - The vertical field of view, in degrees.
|
|
692
|
-
* @param aspect - The viewport's width divided by its height.
|
|
693
|
-
* @param near - The near plane distance, in metres.
|
|
694
|
-
* @param far - The far plane distance, in metres.
|
|
695
|
-
* @returns A new matrix. **Allocates.**
|
|
696
|
-
*/
|
|
697
|
-
static perspectiveLH(fovDegrees, aspect, near, far) {
|
|
698
|
-
return Mat4.perspectiveLHToRef(fovDegrees, aspect, near, far, new Mat4());
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Writes a left-handed perspective projection into `out`, matching Babylon Lite's
|
|
702
|
-
* `mat4PerspectiveLHToRef` — which is a **reverse-depth** projection: the near plane maps to
|
|
703
|
-
* clip-space depth 1 and the far plane to 0, the arrangement that keeps float depth precise.
|
|
704
|
-
*
|
|
705
|
-
* @param fovDegrees - The vertical field of view, in degrees.
|
|
706
|
-
* @param aspect - The viewport's width divided by its height.
|
|
707
|
-
* @param near - The near plane distance, in metres.
|
|
708
|
-
* @param far - The far plane distance, in metres.
|
|
709
|
-
* @param out - The matrix to write.
|
|
710
|
-
* @returns `out`.
|
|
711
|
-
*/
|
|
712
|
-
static perspectiveLHToRef(fovDegrees, aspect, near, far, out) {
|
|
713
|
-
const cot = 1 / Math.tan(degToRad(fovDegrees) * .5);
|
|
714
|
-
const range = far - near;
|
|
715
|
-
const e = out.elements;
|
|
716
|
-
e[0] = cot / aspect;
|
|
717
|
-
e[1] = 0;
|
|
718
|
-
e[2] = 0;
|
|
719
|
-
e[3] = 0;
|
|
720
|
-
e[4] = 0;
|
|
721
|
-
e[5] = cot;
|
|
722
|
-
e[6] = 0;
|
|
723
|
-
e[7] = 0;
|
|
724
|
-
e[8] = 0;
|
|
725
|
-
e[9] = 0;
|
|
726
|
-
e[10] = -near / range;
|
|
727
|
-
e[11] = 1;
|
|
728
|
-
e[12] = 0;
|
|
729
|
-
e[13] = 0;
|
|
730
|
-
e[14] = far * near / range;
|
|
731
|
-
e[15] = 0;
|
|
732
|
-
return out;
|
|
733
|
-
}
|
|
734
|
-
/**
|
|
735
|
-
* Builds a centred left-handed orthographic projection.
|
|
736
|
-
*
|
|
737
|
-
* @param width - The view width, in metres.
|
|
738
|
-
* @param height - The view height, in metres.
|
|
739
|
-
* @param near - The near plane distance, in metres.
|
|
740
|
-
* @param far - The far plane distance, in metres.
|
|
741
|
-
* @returns A new matrix. **Allocates.**
|
|
742
|
-
*/
|
|
743
|
-
static orthoLH(width, height, near, far) {
|
|
744
|
-
return Mat4.orthoLHToRef(width, height, near, far, new Mat4());
|
|
745
|
-
}
|
|
746
|
-
/**
|
|
747
|
-
* Writes a centred left-handed orthographic projection into `out`, with the same reverse-depth
|
|
748
|
-
* convention as {@link Mat4.perspectiveLHToRef}.
|
|
749
|
-
*
|
|
750
|
-
* @param width - The view width, in metres.
|
|
751
|
-
* @param height - The view height, in metres.
|
|
752
|
-
* @param near - The near plane distance, in metres.
|
|
753
|
-
* @param far - The far plane distance, in metres.
|
|
754
|
-
* @param out - The matrix to write.
|
|
755
|
-
* @returns `out`.
|
|
756
|
-
*/
|
|
757
|
-
static orthoLHToRef(width, height, near, far, out) {
|
|
758
|
-
const halfWidth = width * .5;
|
|
759
|
-
const halfHeight = height * .5;
|
|
760
|
-
return Mat4.orthoOffCenterLHToRef(-halfWidth, halfWidth, -halfHeight, halfHeight, near, far, out);
|
|
761
|
-
}
|
|
762
|
-
/**
|
|
763
|
-
* Writes an off-centre left-handed orthographic projection into `out`, reproducing Babylon Lite's
|
|
764
|
-
* `mat4OrthoOffCenterLHToRef` (reverse depth).
|
|
765
|
-
*
|
|
766
|
-
* @param left - The left clip plane, in metres.
|
|
767
|
-
* @param right - The right clip plane, in metres.
|
|
768
|
-
* @param bottom - The bottom clip plane, in metres.
|
|
769
|
-
* @param top - The top clip plane, in metres.
|
|
770
|
-
* @param near - The near plane distance, in metres.
|
|
771
|
-
* @param far - The far plane distance, in metres.
|
|
772
|
-
* @param out - The matrix to write.
|
|
773
|
-
* @returns `out`.
|
|
774
|
-
*/
|
|
775
|
-
static orthoOffCenterLHToRef(left, right, bottom, top, near, far, out) {
|
|
776
|
-
const range = far - near;
|
|
777
|
-
const e = out.elements;
|
|
778
|
-
e[0] = 2 / (right - left);
|
|
779
|
-
e[1] = 0;
|
|
780
|
-
e[2] = 0;
|
|
781
|
-
e[3] = 0;
|
|
782
|
-
e[4] = 0;
|
|
783
|
-
e[5] = 2 / (top - bottom);
|
|
784
|
-
e[6] = 0;
|
|
785
|
-
e[7] = 0;
|
|
786
|
-
e[8] = 0;
|
|
787
|
-
e[9] = 0;
|
|
788
|
-
e[10] = -1 / range;
|
|
789
|
-
e[11] = 0;
|
|
790
|
-
e[12] = (left + right) / (left - right);
|
|
791
|
-
e[13] = (top + bottom) / (bottom - top);
|
|
792
|
-
e[14] = far / range;
|
|
793
|
-
e[15] = 1;
|
|
794
|
-
return out;
|
|
795
|
-
}
|
|
796
|
-
/**
|
|
797
|
-
* Reads a matrix's translation.
|
|
798
|
-
*
|
|
799
|
-
* @param m - The matrix to read.
|
|
800
|
-
* @param out - The vector to write.
|
|
801
|
-
* @returns `out`.
|
|
802
|
-
*/
|
|
803
|
-
static getTranslationToRef(m, out) {
|
|
804
|
-
out.set(m[12] ?? 0, m[13] ?? 0, m[14] ?? 0);
|
|
805
|
-
return out;
|
|
806
|
-
}
|
|
807
|
-
/**
|
|
808
|
-
* Reads a matrix's per-axis scale as the lengths of its basis columns, negating Y for a mirrored
|
|
809
|
-
* matrix exactly as {@link Mat4.decomposeToRef} does.
|
|
810
|
-
*
|
|
811
|
-
* @param m - The matrix to read.
|
|
812
|
-
* @param out - The vector to write.
|
|
813
|
-
* @returns `out`.
|
|
814
|
-
*/
|
|
815
|
-
static getScaleToRef(m, out) {
|
|
816
|
-
const sx = Math.hypot(m[0] ?? 0, m[1] ?? 0, m[2] ?? 0);
|
|
817
|
-
const syAbs = Math.hypot(m[4] ?? 0, m[5] ?? 0, m[6] ?? 0);
|
|
818
|
-
const sz = Math.hypot(m[8] ?? 0, m[9] ?? 0, m[10] ?? 0);
|
|
819
|
-
out.set(sx, basisDeterminant(m) < 0 ? -syAbs : syAbs, sz);
|
|
820
|
-
return out;
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
|
-
* Reads a matrix's rotation, dividing the scale out of the basis first.
|
|
824
|
-
*
|
|
825
|
-
* @param m - The matrix to read.
|
|
826
|
-
* @param out - The quaternion to write. Left untouched when a basis column has zero length.
|
|
827
|
-
* @returns `out`.
|
|
828
|
-
*/
|
|
829
|
-
static getRotationToRef(m, out) {
|
|
830
|
-
const m0 = m[0] ?? 0;
|
|
831
|
-
const m1 = m[1] ?? 0;
|
|
832
|
-
const m2 = m[2] ?? 0;
|
|
833
|
-
const m4 = m[4] ?? 0;
|
|
834
|
-
const m5 = m[5] ?? 0;
|
|
835
|
-
const m6 = m[6] ?? 0;
|
|
836
|
-
const m8 = m[8] ?? 0;
|
|
837
|
-
const m9 = m[9] ?? 0;
|
|
838
|
-
const m10 = m[10] ?? 0;
|
|
839
|
-
const sx = Math.hypot(m0, m1, m2);
|
|
840
|
-
const syAbs = Math.hypot(m4, m5, m6);
|
|
841
|
-
const sz = Math.hypot(m8, m9, m10);
|
|
842
|
-
if (sx <= 1e-8 || syAbs <= 1e-8 || sz <= 1e-8) return out;
|
|
843
|
-
const invSx = 1 / sx;
|
|
844
|
-
const invSy = 1 / (basisDeterminant(m) < 0 ? -syAbs : syAbs);
|
|
845
|
-
const invSz = 1 / sz;
|
|
846
|
-
basisToQuatToRef(m0 * invSx, m4 * invSy, m8 * invSz, m1 * invSx, m5 * invSy, m9 * invSz, m2 * invSx, m6 * invSy, m10 * invSz, out);
|
|
847
|
-
const invLength = 1 / Math.hypot(out.x, out.y, out.z, out.w);
|
|
848
|
-
out.set(out.x * invLength, out.y * invLength, out.z * invLength, out.w * invLength);
|
|
849
|
-
return out;
|
|
850
|
-
}
|
|
851
|
-
/**
|
|
852
|
-
* Transforms a point by a matrix, applying translation and the perspective divide.
|
|
853
|
-
*
|
|
854
|
-
* @param m - The transformation.
|
|
855
|
-
* @param point - The point to transform, in metres.
|
|
856
|
-
* @param out - The vector to write; may alias `point`.
|
|
857
|
-
* @returns `out`.
|
|
858
|
-
*/
|
|
859
|
-
static transformPointToRef(m, point, out) {
|
|
860
|
-
const x = point.x;
|
|
861
|
-
const y = point.y;
|
|
862
|
-
const z = point.z;
|
|
863
|
-
const rx = x * (m[0] ?? 0) + y * (m[4] ?? 0) + z * (m[8] ?? 0) + (m[12] ?? 0);
|
|
864
|
-
const ry = x * (m[1] ?? 0) + y * (m[5] ?? 0) + z * (m[9] ?? 0) + (m[13] ?? 0);
|
|
865
|
-
const rz = x * (m[2] ?? 0) + y * (m[6] ?? 0) + z * (m[10] ?? 0) + (m[14] ?? 0);
|
|
866
|
-
const invW = 1 / (x * (m[3] ?? 0) + y * (m[7] ?? 0) + z * (m[11] ?? 0) + (m[15] ?? 0));
|
|
867
|
-
out.set(rx * invW, ry * invW, rz * invW);
|
|
868
|
-
return out;
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* Transforms a direction by a matrix, ignoring translation. Note that this is the plain basis
|
|
872
|
-
* transform: a non-uniformly scaled matrix needs its inverse-transpose to keep normals correct.
|
|
873
|
-
*
|
|
874
|
-
* @param m - The transformation.
|
|
875
|
-
* @param direction - The direction to transform.
|
|
876
|
-
* @param out - The vector to write; may alias `direction`.
|
|
877
|
-
* @returns `out`.
|
|
878
|
-
*/
|
|
879
|
-
static transformDirectionToRef(m, direction, out) {
|
|
880
|
-
const x = direction.x;
|
|
881
|
-
const y = direction.y;
|
|
882
|
-
const z = direction.z;
|
|
883
|
-
out.set(x * (m[0] ?? 0) + y * (m[4] ?? 0) + z * (m[8] ?? 0), x * (m[1] ?? 0) + y * (m[5] ?? 0) + z * (m[9] ?? 0), x * (m[2] ?? 0) + y * (m[6] ?? 0) + z * (m[10] ?? 0));
|
|
884
|
-
return out;
|
|
885
|
-
}
|
|
886
|
-
/**
|
|
887
|
-
* Compares two matrices element by element, with a tolerance.
|
|
888
|
-
*
|
|
889
|
-
* @param a - The first matrix.
|
|
890
|
-
* @param b - The second matrix.
|
|
891
|
-
* @param epsilon - The largest per-element difference still considered equal.
|
|
892
|
-
* @returns `true` when every element matches within `epsilon`.
|
|
893
|
-
*/
|
|
894
|
-
static equalsWithEpsilon(a, b, epsilon = EPSILON) {
|
|
895
|
-
for (let i = 0; i < 16; i++) if (Math.abs((a[i] ?? 0) - (b[i] ?? 0)) > epsilon) return false;
|
|
896
|
-
return true;
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
/**
|
|
900
|
-
* The zero translation {@link Mat4.fromQuatToRef} composes with. Module-scope constant, frozen so it
|
|
901
|
-
* can never be written through.
|
|
902
|
-
*/
|
|
903
|
-
const ZERO_TRANSLATION = Object.freeze({
|
|
904
|
-
x: 0,
|
|
905
|
-
y: 0,
|
|
906
|
-
z: 0
|
|
907
|
-
});
|
|
908
|
-
/**
|
|
909
|
-
* The unit scale {@link Mat4.fromQuatToRef} composes with.
|
|
910
|
-
*/
|
|
911
|
-
const UNIT_SCALE = Object.freeze({
|
|
912
|
-
x: 1,
|
|
913
|
-
y: 1,
|
|
914
|
-
z: 1
|
|
915
|
-
});
|
|
916
|
-
/**
|
|
917
|
-
* A frozen identity matrix, for the common case of "no transform". It is a plain {@link Mat4Like}
|
|
918
|
-
* rather than a {@link Mat4} because a `Float32Array` cannot be frozen — pass it to anything that
|
|
919
|
-
* reads a matrix, and use `new Mat4()` when you need one you can write to.
|
|
920
|
-
*
|
|
921
|
-
* @example
|
|
922
|
-
* ```ts
|
|
923
|
-
* Mat4.transformPointToRef(MAT4_IDENTITY, point, out); // copies the point
|
|
924
|
-
* ```
|
|
925
|
-
*
|
|
926
|
-
* @public
|
|
927
|
-
*/
|
|
928
|
-
const MAT4_IDENTITY = Object.freeze({
|
|
929
|
-
length: 16,
|
|
930
|
-
0: 1,
|
|
931
|
-
1: 0,
|
|
932
|
-
2: 0,
|
|
933
|
-
3: 0,
|
|
934
|
-
4: 0,
|
|
935
|
-
5: 1,
|
|
936
|
-
6: 0,
|
|
937
|
-
7: 0,
|
|
938
|
-
8: 0,
|
|
939
|
-
9: 0,
|
|
940
|
-
10: 1,
|
|
941
|
-
11: 0,
|
|
942
|
-
12: 0,
|
|
943
|
-
13: 0,
|
|
944
|
-
14: 0,
|
|
945
|
-
15: 1
|
|
946
|
-
});
|
|
947
|
-
//#endregion
|
|
948
4
|
//#region src/lite/node.ts
|
|
949
5
|
/** The single key ignifx owns inside Lite's open `metadata` record. */
|
|
950
6
|
const METADATA_KEY = "ignifx";
|
|
@@ -2453,6 +1509,6 @@ const VEC3_BACKWARD = Object.freeze({
|
|
|
2453
1509
|
z: -1
|
|
2454
1510
|
});
|
|
2455
1511
|
//#endregion
|
|
2456
|
-
export {
|
|
1512
|
+
export { setMeshReceiveShadows as A, localPosition as B, overrideSubtreeMaterials as C, setMeshId as D, setMeshBounds as E, updateMeshPositions$1 as F, readWorldMatrix as G, localScale as H, updateMeshUvs$1 as I, setNodeSelfVisible as J, reparentKeepingWorld as K, createNode as L, setMeshSubtreeVisible as M, updateMeshColors$1 as N, setMeshMaterial as O, updateMeshNormals$1 as P, disposeNode as R, disposeMeshTemplate as S, removeMeshFromScene as T, parentNode as U, localRotation as V, readNodeTag as W, worldMatrixVersion as X, tagNode as Y, createMeshFromGeometry as _, VEC3_ONE as a, createTorusMesh as b, VEC3_ZERO as c, cloneMeshUnderNode as d, collectSubtreeMeshes as f, createGroundMesh as g, createCylinderMesh as h, VEC3_LEFT as i, setMeshRenderOrder as j, setMeshPickable as k, Vec3 as l, createCapsuleMesh as m, VEC3_DOWN as n, VEC3_RIGHT as o, createBoxMesh as p, setNodeName as q, VEC3_FORWARD as r, VEC3_UP as s, VEC3_BACKWARD as t, addMeshToScene as u, createPlaneMesh as v, recomputeMeshBounds as w, detachMeshBounds as x, createSphereMesh as y, linkParent as z };
|
|
2457
1513
|
|
|
2458
|
-
//# sourceMappingURL=vec3-
|
|
1514
|
+
//# sourceMappingURL=vec3-D-0Y2mzE.js.map
|