@manycore/aholo-splat-transform 1.2.8 → 1.2.10

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +124 -113
  2. package/README.md +39 -39
  3. package/THIRD_PARTY_LICENSES.txt +1373 -1373
  4. package/bin/cli.js +125 -118
  5. package/dist/SplatData.d.ts +67 -67
  6. package/dist/SplatData.js +167 -150
  7. package/dist/constant.d.ts +3 -3
  8. package/dist/constant.js +13 -13
  9. package/dist/file/IFile.d.ts +5 -5
  10. package/dist/file/IFile.js +1 -1
  11. package/dist/file/esz.d.ts +11 -11
  12. package/dist/file/esz.js +337 -322
  13. package/dist/file/index.d.ts +8 -8
  14. package/dist/file/index.js +7 -7
  15. package/dist/file/ksplat.d.ts +12 -12
  16. package/dist/file/ksplat.js +293 -231
  17. package/dist/file/lcc.d.ts +11 -11
  18. package/dist/file/lcc.js +161 -158
  19. package/dist/file/ply.d.ts +13 -13
  20. package/dist/file/ply.js +439 -390
  21. package/dist/file/sog.d.ts +80 -80
  22. package/dist/file/sog.js +525 -494
  23. package/dist/file/splat.d.ts +6 -6
  24. package/dist/file/splat.js +119 -99
  25. package/dist/file/spz.d.ts +11 -11
  26. package/dist/file/spz.js +597 -583
  27. package/dist/file/voxel.d.ts +43 -37
  28. package/dist/file/voxel.js +411 -280
  29. package/dist/index.d.ts +33 -33
  30. package/dist/index.js +54 -54
  31. package/dist/native/index.d.ts +54 -54
  32. package/dist/native/index.js +122 -129
  33. package/dist/native/utils.d.ts +1 -0
  34. package/dist/native/utils.js +54 -0
  35. package/dist/tasks/AutoChunkLodTask.d.ts +13 -13
  36. package/dist/tasks/AutoChunkLodTask.js +117 -117
  37. package/dist/tasks/AutoLodTask.d.ts +10 -10
  38. package/dist/tasks/AutoLodTask.js +20 -20
  39. package/dist/tasks/BaseTask.d.ts +15 -15
  40. package/dist/tasks/BaseTask.js +5 -5
  41. package/dist/tasks/FlexLodTask.d.ts +12 -12
  42. package/dist/tasks/FlexLodTask.js +54 -44
  43. package/dist/tasks/ModifyTask.d.ts +9 -9
  44. package/dist/tasks/ModifyTask.js +166 -156
  45. package/dist/tasks/ReadTask.d.ts +9 -9
  46. package/dist/tasks/ReadTask.js +29 -29
  47. package/dist/tasks/SkeletonLodTask.d.ts +10 -10
  48. package/dist/tasks/SkeletonLodTask.js +176 -156
  49. package/dist/tasks/VoxelTask.d.ts +35 -30
  50. package/dist/tasks/VoxelTask.js +40 -37
  51. package/dist/tasks/WriteTask.d.ts +12 -12
  52. package/dist/tasks/WriteTask.js +70 -70
  53. package/dist/utils/BufferReader.d.ts +12 -12
  54. package/dist/utils/BufferReader.js +45 -45
  55. package/dist/utils/Logger.d.ts +11 -11
  56. package/dist/utils/Logger.js +40 -40
  57. package/dist/utils/StreamChunkDecoder.d.ts +16 -16
  58. package/dist/utils/StreamChunkDecoder.js +31 -31
  59. package/dist/utils/index.d.ts +27 -27
  60. package/dist/utils/index.js +101 -101
  61. package/dist/utils/k-means.d.ts +4 -4
  62. package/dist/utils/k-means.js +340 -341
  63. package/dist/utils/math.d.ts +46 -46
  64. package/dist/utils/math.js +350 -346
  65. package/dist/utils/quantize-1d.d.ts +4 -4
  66. package/dist/utils/quantize-1d.js +164 -164
  67. package/dist/utils/sh-rotate.d.ts +2 -2
  68. package/dist/utils/sh-rotate.js +236 -175
  69. package/dist/utils/splat.d.ts +21 -21
  70. package/dist/utils/splat.js +397 -387
  71. package/dist/utils/voxel/binary.d.ts +8 -0
  72. package/dist/utils/voxel/binary.js +176 -0
  73. package/dist/utils/voxel/common.d.ts +178 -162
  74. package/dist/utils/voxel/common.js +1752 -1682
  75. package/dist/utils/voxel/coplanar-merge.d.ts +63 -63
  76. package/dist/utils/voxel/coplanar-merge.js +818 -819
  77. package/dist/utils/voxel/filter-cluster.d.ts +20 -0
  78. package/dist/utils/voxel/filter-cluster.js +628 -0
  79. package/dist/utils/voxel/gpu-dilation.d.ts +2 -2
  80. package/dist/utils/voxel/gpu-dilation.js +677 -656
  81. package/dist/utils/voxel/marching-cubes.d.ts +42 -42
  82. package/dist/utils/voxel/marching-cubes.js +1645 -1657
  83. package/dist/utils/voxel/mesh.d.ts +3 -3
  84. package/dist/utils/voxel/mesh.js +130 -130
  85. package/dist/utils/voxel/nav.d.ts +29 -29
  86. package/dist/utils/voxel/nav.js +1068 -1043
  87. package/dist/utils/voxel/postprocess.d.ts +23 -23
  88. package/dist/utils/voxel/postprocess.js +408 -375
  89. package/dist/utils/voxel/voxel-faces.d.ts +18 -18
  90. package/dist/utils/voxel/voxel-faces.js +662 -663
  91. package/dist/utils/voxel/voxelize.d.ts +34 -33
  92. package/dist/utils/voxel/voxelize.js +1208 -1193
  93. package/dist/utils/webgpu.d.ts +8 -8
  94. package/dist/utils/webgpu.js +122 -122
  95. package/package.json +38 -39
  96. package/dist/native/cpp/bin/linux/binding.node +0 -0
  97. package/dist/native/cpp/bin/windows/binding.node +0 -0
@@ -1,346 +1,350 @@
1
- export class Quaternion {
2
- static { this.ONE = new Quaternion(0, 0, 0, 1); }
3
- constructor(x, y, z, w) {
4
- this.x = x;
5
- this.y = y;
6
- this.z = z;
7
- this.w = w;
8
- }
9
- set(x, y, z, w) {
10
- this.x = x;
11
- this.y = y;
12
- this.z = z;
13
- this.w = w;
14
- return this;
15
- }
16
- equals(q) {
17
- return (q.x === this.x) && (q.y === this.y) && (q.z === this.z) && (q.w === this.w);
18
- }
19
- normalize() {
20
- const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
21
- if (length === 0) {
22
- return this;
23
- }
24
- const invLength = (1 / length) * (this.w < 0 ? -1 : 1);
25
- this.x *= invLength;
26
- this.y *= invLength;
27
- this.z *= invLength;
28
- this.w *= invLength;
29
- return this;
30
- }
31
- multiply(q) {
32
- return this.multiplyQuaternions(this, q);
33
- }
34
- premultiply(q) {
35
- return this.multiplyQuaternions(q, this);
36
- }
37
- multiplyQuaternions(a, b) {
38
- // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
39
- const qax = a.x;
40
- const qay = a.y;
41
- const qaz = a.z;
42
- const qaw = a.w;
43
- const qbx = b.x;
44
- const qby = b.y;
45
- const qbz = b.z;
46
- const qbw = b.w;
47
- this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
48
- this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
49
- this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
50
- this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
51
- return this;
52
- }
53
- setRotationMatrix(m) {
54
- // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
55
- // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
56
- const te = m.elements;
57
- const m11 = te[0];
58
- const m12 = te[4];
59
- const m13 = te[8];
60
- const m21 = te[1];
61
- const m22 = te[5];
62
- const m23 = te[9];
63
- const m31 = te[2];
64
- const m32 = te[6];
65
- const m33 = te[10];
66
- const trace = m11 + m22 + m33;
67
- let s;
68
- if (trace > 0) {
69
- s = 0.5 / Math.sqrt(trace + 1.0);
70
- this.w = 0.25 / s;
71
- this.x = (m32 - m23) * s;
72
- this.y = (m13 - m31) * s;
73
- this.z = (m21 - m12) * s;
74
- }
75
- else if (m11 > m22 && m11 > m33) {
76
- s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
77
- this.w = (m32 - m23) / s;
78
- this.x = 0.25 * s;
79
- this.y = (m12 + m21) / s;
80
- this.z = (m13 + m31) / s;
81
- }
82
- else if (m22 > m33) {
83
- s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
84
- this.w = (m13 - m31) / s;
85
- this.x = (m12 + m21) / s;
86
- this.y = 0.25 * s;
87
- this.z = (m23 + m32) / s;
88
- }
89
- else {
90
- s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
91
- this.w = (m21 - m12) / s;
92
- this.x = (m13 + m31) / s;
93
- this.y = (m23 + m32) / s;
94
- this.z = 0.25 * s;
95
- }
96
- return this;
97
- }
98
- }
99
- export class Vector3 {
100
- static { this.ONE = new Vector3(1, 1, 1); }
101
- constructor(x, y, z) {
102
- this.x = x;
103
- this.y = y;
104
- this.z = z;
105
- }
106
- set(x, y, z) {
107
- this.x = x;
108
- this.y = y;
109
- this.z = z;
110
- return this;
111
- }
112
- length() {
113
- return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
114
- }
115
- equals(v) {
116
- return (v.x === this.x) && (v.y === this.y) && (v.z === this.z);
117
- }
118
- mul(v) {
119
- this.x *= v.x;
120
- this.y *= v.y;
121
- this.z *= v.z;
122
- return this;
123
- }
124
- applyMatrix4(m) {
125
- const { x, y, z } = this;
126
- const e = m.elements;
127
- const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
128
- this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
129
- this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
130
- this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
131
- return this;
132
- }
133
- clone() {
134
- return new Vector3(this.x, this.y, this.z);
135
- }
136
- }
137
- export class Matrix4 {
138
- static { this.ONE = new Matrix4(); }
139
- constructor(elements, isRow = false) {
140
- this.elements = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
141
- if (elements) {
142
- this.set(elements);
143
- }
144
- if (isRow) {
145
- this.transpose();
146
- }
147
- }
148
- set(elements) {
149
- for (let i = 0; i < 16; i++) {
150
- this.elements[i] = elements[i];
151
- }
152
- return this;
153
- }
154
- equals(matrix) {
155
- const te = this.elements;
156
- const me = matrix.elements;
157
- for (let i = 0; i < 16; i++) {
158
- if (te[i] !== me[i]) {
159
- return false;
160
- }
161
- }
162
- return true;
163
- }
164
- determinant() {
165
- const te = this.elements;
166
- const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12], n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13], n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14], n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
167
- // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
168
- return (n41 * (+n14 * n23 * n32
169
- - n13 * n24 * n32
170
- - n14 * n22 * n33
171
- + n12 * n24 * n33
172
- + n13 * n22 * n34
173
- - n12 * n23 * n34) +
174
- n42 * (+n11 * n23 * n34
175
- - n11 * n24 * n33
176
- + n14 * n21 * n33
177
- - n13 * n21 * n34
178
- + n13 * n24 * n31
179
- - n14 * n23 * n31) +
180
- n43 * (+n11 * n24 * n32
181
- - n11 * n22 * n34
182
- - n14 * n21 * n32
183
- + n12 * n21 * n34
184
- + n14 * n22 * n31
185
- - n12 * n24 * n31) +
186
- n44 * (-n13 * n22 * n31
187
- - n11 * n23 * n32
188
- + n11 * n22 * n33
189
- + n13 * n21 * n32
190
- - n12 * n21 * n33
191
- + n12 * n23 * n31));
192
- }
193
- multiply(m) {
194
- return this.multiplyMatrices(this, m);
195
- }
196
- multiplyMatrices(a, b) {
197
- const te = this.elements;
198
- const ae = a.elements;
199
- const be = b.elements;
200
- const a11 = ae[0];
201
- const a12 = ae[4];
202
- const a13 = ae[8];
203
- const a14 = ae[12];
204
- const a21 = ae[1];
205
- const a22 = ae[5];
206
- const a23 = ae[9];
207
- const a24 = ae[13];
208
- const a31 = ae[2];
209
- const a32 = ae[6];
210
- const a33 = ae[10];
211
- const a34 = ae[14];
212
- const a41 = ae[3];
213
- const a42 = ae[7];
214
- const a43 = ae[11];
215
- const a44 = ae[15];
216
- const b11 = be[0];
217
- const b12 = be[4];
218
- const b13 = be[8];
219
- const b14 = be[12];
220
- const b21 = be[1];
221
- const b22 = be[5];
222
- const b23 = be[9];
223
- const b24 = be[13];
224
- const b31 = be[2];
225
- const b32 = be[6];
226
- const b33 = be[10];
227
- const b34 = be[14];
228
- const b41 = be[3];
229
- const b42 = be[7];
230
- const b43 = be[11];
231
- const b44 = be[15];
232
- te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
233
- te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
234
- te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
235
- te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
236
- te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
237
- te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
238
- te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
239
- te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
240
- te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
241
- te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
242
- te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
243
- te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
244
- te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
245
- te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
246
- te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
247
- te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
248
- return this;
249
- }
250
- compose(position, quaternion, scale) {
251
- const te = this.elements;
252
- const x = quaternion.x, y = quaternion.y, z = quaternion.z, w = quaternion.w, x2 = x + x, y2 = y + y, z2 = z + z, xx = x * x2, xy = x * y2, xz = x * z2, yy = y * y2, yz = y * z2, zz = z * z2, wx = w * x2, wy = w * y2, wz = w * z2, sx = scale.x, sy = scale.y, sz = scale.z;
253
- te[0] = (1 - (yy + zz)) * sx;
254
- te[1] = (xy + wz) * sx;
255
- te[2] = (xz - wy) * sx;
256
- te[3] = 0;
257
- te[4] = (xy - wz) * sy;
258
- te[5] = (1 - (xx + zz)) * sy;
259
- te[6] = (yz + wx) * sy;
260
- te[7] = 0;
261
- te[8] = (xz + wy) * sz;
262
- te[9] = (yz - wx) * sz;
263
- te[10] = (1 - (xx + yy)) * sz;
264
- te[11] = 0;
265
- te[12] = position.x;
266
- te[13] = position.y;
267
- te[14] = position.z;
268
- te[15] = 1;
269
- return this;
270
- }
271
- decompose(position, quaternion, scale) {
272
- const te = this.elements;
273
- let sx = tmpVec.set(te[0], te[1], te[2]).length();
274
- const sy = tmpVec.set(te[4], te[5], te[6]).length();
275
- const sz = tmpVec.set(te[8], te[9], te[10]).length();
276
- const det = this.determinant();
277
- if (det < 0) {
278
- sx *= -1;
279
- }
280
- position.set(te[12], te[13], te[14]);
281
- const invSX = 1 / sx;
282
- const invSY = 1 / sy;
283
- const invSZ = 1 / sz;
284
- tmpMat4.set(this.elements);
285
- tmpMat4.elements[0] *= invSX;
286
- tmpMat4.elements[1] *= invSX;
287
- tmpMat4.elements[2] *= invSX;
288
- tmpMat4.elements[4] *= invSY;
289
- tmpMat4.elements[5] *= invSY;
290
- tmpMat4.elements[6] *= invSY;
291
- tmpMat4.elements[8] *= invSZ;
292
- tmpMat4.elements[9] *= invSZ;
293
- tmpMat4.elements[10] *= invSZ;
294
- quaternion.setRotationMatrix(tmpMat4);
295
- scale.set(sx, sy, sz);
296
- return this;
297
- }
298
- transpose() {
299
- const te = this.elements;
300
- let tmp;
301
- tmp = te[1];
302
- te[1] = te[4];
303
- te[4] = tmp;
304
- tmp = te[2];
305
- te[2] = te[8];
306
- te[8] = tmp;
307
- tmp = te[6];
308
- te[6] = te[9];
309
- te[9] = tmp;
310
- tmp = te[3];
311
- te[3] = te[12];
312
- te[12] = tmp;
313
- tmp = te[7];
314
- te[7] = te[13];
315
- te[13] = tmp;
316
- tmp = te[11];
317
- te[11] = te[14];
318
- te[14] = tmp;
319
- return this;
320
- }
321
- }
322
- export class Matrix3 {
323
- constructor() {
324
- this.elements = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
325
- }
326
- set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
327
- const te = this.elements;
328
- te[0] = n11;
329
- te[1] = n21;
330
- te[2] = n31;
331
- te[3] = n12;
332
- te[4] = n22;
333
- te[5] = n32;
334
- te[6] = n13;
335
- te[7] = n23;
336
- te[8] = n33;
337
- return this;
338
- }
339
- setFromMatrix4(m) {
340
- const me = m.elements;
341
- this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
342
- return this;
343
- }
344
- }
345
- const tmpVec = new Vector3(0, 0, 0);
346
- const tmpMat4 = new Matrix4();
1
+ export class Quaternion {
2
+ static { this.ONE = new Quaternion(0, 0, 0, 1); }
3
+ constructor(x, y, z, w) {
4
+ this.x = x;
5
+ this.y = y;
6
+ this.z = z;
7
+ this.w = w;
8
+ }
9
+ set(x, y, z, w) {
10
+ this.x = x;
11
+ this.y = y;
12
+ this.z = z;
13
+ this.w = w;
14
+ return this;
15
+ }
16
+ equals(q) {
17
+ return q.x === this.x && q.y === this.y && q.z === this.z && q.w === this.w;
18
+ }
19
+ normalize() {
20
+ const length = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);
21
+ if (length === 0) {
22
+ return this;
23
+ }
24
+ const invLength = (1 / length) * (this.w < 0 ? -1 : 1);
25
+ this.x *= invLength;
26
+ this.y *= invLength;
27
+ this.z *= invLength;
28
+ this.w *= invLength;
29
+ return this;
30
+ }
31
+ multiply(q) {
32
+ return this.multiplyQuaternions(this, q);
33
+ }
34
+ premultiply(q) {
35
+ return this.multiplyQuaternions(q, this);
36
+ }
37
+ multiplyQuaternions(a, b) {
38
+ // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
39
+ const qax = a.x;
40
+ const qay = a.y;
41
+ const qaz = a.z;
42
+ const qaw = a.w;
43
+ const qbx = b.x;
44
+ const qby = b.y;
45
+ const qbz = b.z;
46
+ const qbw = b.w;
47
+ this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
48
+ this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
49
+ this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
50
+ this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
51
+ return this;
52
+ }
53
+ setRotationMatrix(m) {
54
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
55
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
56
+ const te = m.elements;
57
+ const m11 = te[0];
58
+ const m12 = te[4];
59
+ const m13 = te[8];
60
+ const m21 = te[1];
61
+ const m22 = te[5];
62
+ const m23 = te[9];
63
+ const m31 = te[2];
64
+ const m32 = te[6];
65
+ const m33 = te[10];
66
+ const trace = m11 + m22 + m33;
67
+ let s;
68
+ if (trace > 0) {
69
+ s = 0.5 / Math.sqrt(trace + 1.0);
70
+ this.w = 0.25 / s;
71
+ this.x = (m32 - m23) * s;
72
+ this.y = (m13 - m31) * s;
73
+ this.z = (m21 - m12) * s;
74
+ }
75
+ else if (m11 > m22 && m11 > m33) {
76
+ s = 2.0 * Math.sqrt(1.0 + m11 - m22 - m33);
77
+ this.w = (m32 - m23) / s;
78
+ this.x = 0.25 * s;
79
+ this.y = (m12 + m21) / s;
80
+ this.z = (m13 + m31) / s;
81
+ }
82
+ else if (m22 > m33) {
83
+ s = 2.0 * Math.sqrt(1.0 + m22 - m11 - m33);
84
+ this.w = (m13 - m31) / s;
85
+ this.x = (m12 + m21) / s;
86
+ this.y = 0.25 * s;
87
+ this.z = (m23 + m32) / s;
88
+ }
89
+ else {
90
+ s = 2.0 * Math.sqrt(1.0 + m33 - m11 - m22);
91
+ this.w = (m21 - m12) / s;
92
+ this.x = (m13 + m31) / s;
93
+ this.y = (m23 + m32) / s;
94
+ this.z = 0.25 * s;
95
+ }
96
+ return this;
97
+ }
98
+ }
99
+ export class Vector3 {
100
+ static { this.ONE = new Vector3(1, 1, 1); }
101
+ constructor(x, y, z) {
102
+ this.x = x;
103
+ this.y = y;
104
+ this.z = z;
105
+ }
106
+ set(x, y, z) {
107
+ this.x = x;
108
+ this.y = y;
109
+ this.z = z;
110
+ return this;
111
+ }
112
+ length() {
113
+ return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
114
+ }
115
+ equals(v) {
116
+ return v.x === this.x && v.y === this.y && v.z === this.z;
117
+ }
118
+ mul(v) {
119
+ this.x *= v.x;
120
+ this.y *= v.y;
121
+ this.z *= v.z;
122
+ return this;
123
+ }
124
+ applyMatrix4(m) {
125
+ const { x, y, z } = this;
126
+ const e = m.elements;
127
+ const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
128
+ this.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
129
+ this.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
130
+ this.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;
131
+ return this;
132
+ }
133
+ clone() {
134
+ return new Vector3(this.x, this.y, this.z);
135
+ }
136
+ }
137
+ export class Matrix4 {
138
+ static { this.ONE = new Matrix4(); }
139
+ constructor(elements, isRow = false) {
140
+ this.elements = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
141
+ if (elements) {
142
+ this.set(elements);
143
+ }
144
+ if (isRow) {
145
+ this.transpose();
146
+ }
147
+ }
148
+ set(elements) {
149
+ for (let i = 0; i < 16; i++) {
150
+ this.elements[i] = elements[i];
151
+ }
152
+ return this;
153
+ }
154
+ equals(matrix) {
155
+ const te = this.elements;
156
+ const me = matrix.elements;
157
+ for (let i = 0; i < 16; i++) {
158
+ if (te[i] !== me[i]) {
159
+ return false;
160
+ }
161
+ }
162
+ return true;
163
+ }
164
+ determinant() {
165
+ const te = this.elements;
166
+ const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12], n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13], n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14], n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15];
167
+ // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
168
+ return (n41 *
169
+ (+n14 * n23 * n32 -
170
+ n13 * n24 * n32 -
171
+ n14 * n22 * n33 +
172
+ n12 * n24 * n33 +
173
+ n13 * n22 * n34 -
174
+ n12 * n23 * n34) +
175
+ n42 *
176
+ (+n11 * n23 * n34 -
177
+ n11 * n24 * n33 +
178
+ n14 * n21 * n33 -
179
+ n13 * n21 * n34 +
180
+ n13 * n24 * n31 -
181
+ n14 * n23 * n31) +
182
+ n43 *
183
+ (+n11 * n24 * n32 -
184
+ n11 * n22 * n34 -
185
+ n14 * n21 * n32 +
186
+ n12 * n21 * n34 +
187
+ n14 * n22 * n31 -
188
+ n12 * n24 * n31) +
189
+ n44 *
190
+ (-n13 * n22 * n31 -
191
+ n11 * n23 * n32 +
192
+ n11 * n22 * n33 +
193
+ n13 * n21 * n32 -
194
+ n12 * n21 * n33 +
195
+ n12 * n23 * n31));
196
+ }
197
+ multiply(m) {
198
+ return this.multiplyMatrices(this, m);
199
+ }
200
+ multiplyMatrices(a, b) {
201
+ const te = this.elements;
202
+ const ae = a.elements;
203
+ const be = b.elements;
204
+ const a11 = ae[0];
205
+ const a12 = ae[4];
206
+ const a13 = ae[8];
207
+ const a14 = ae[12];
208
+ const a21 = ae[1];
209
+ const a22 = ae[5];
210
+ const a23 = ae[9];
211
+ const a24 = ae[13];
212
+ const a31 = ae[2];
213
+ const a32 = ae[6];
214
+ const a33 = ae[10];
215
+ const a34 = ae[14];
216
+ const a41 = ae[3];
217
+ const a42 = ae[7];
218
+ const a43 = ae[11];
219
+ const a44 = ae[15];
220
+ const b11 = be[0];
221
+ const b12 = be[4];
222
+ const b13 = be[8];
223
+ const b14 = be[12];
224
+ const b21 = be[1];
225
+ const b22 = be[5];
226
+ const b23 = be[9];
227
+ const b24 = be[13];
228
+ const b31 = be[2];
229
+ const b32 = be[6];
230
+ const b33 = be[10];
231
+ const b34 = be[14];
232
+ const b41 = be[3];
233
+ const b42 = be[7];
234
+ const b43 = be[11];
235
+ const b44 = be[15];
236
+ te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
237
+ te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
238
+ te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
239
+ te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
240
+ te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
241
+ te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
242
+ te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
243
+ te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
244
+ te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
245
+ te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
246
+ te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
247
+ te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
248
+ te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
249
+ te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
250
+ te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
251
+ te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
252
+ return this;
253
+ }
254
+ compose(position, quaternion, scale) {
255
+ const te = this.elements;
256
+ const x = quaternion.x, y = quaternion.y, z = quaternion.z, w = quaternion.w, x2 = x + x, y2 = y + y, z2 = z + z, xx = x * x2, xy = x * y2, xz = x * z2, yy = y * y2, yz = y * z2, zz = z * z2, wx = w * x2, wy = w * y2, wz = w * z2, sx = scale.x, sy = scale.y, sz = scale.z;
257
+ te[0] = (1 - (yy + zz)) * sx;
258
+ te[1] = (xy + wz) * sx;
259
+ te[2] = (xz - wy) * sx;
260
+ te[3] = 0;
261
+ te[4] = (xy - wz) * sy;
262
+ te[5] = (1 - (xx + zz)) * sy;
263
+ te[6] = (yz + wx) * sy;
264
+ te[7] = 0;
265
+ te[8] = (xz + wy) * sz;
266
+ te[9] = (yz - wx) * sz;
267
+ te[10] = (1 - (xx + yy)) * sz;
268
+ te[11] = 0;
269
+ te[12] = position.x;
270
+ te[13] = position.y;
271
+ te[14] = position.z;
272
+ te[15] = 1;
273
+ return this;
274
+ }
275
+ decompose(position, quaternion, scale) {
276
+ const te = this.elements;
277
+ let sx = tmpVec.set(te[0], te[1], te[2]).length();
278
+ const sy = tmpVec.set(te[4], te[5], te[6]).length();
279
+ const sz = tmpVec.set(te[8], te[9], te[10]).length();
280
+ const det = this.determinant();
281
+ if (det < 0) {
282
+ sx *= -1;
283
+ }
284
+ position.set(te[12], te[13], te[14]);
285
+ const invSX = 1 / sx;
286
+ const invSY = 1 / sy;
287
+ const invSZ = 1 / sz;
288
+ tmpMat4.set(this.elements);
289
+ tmpMat4.elements[0] *= invSX;
290
+ tmpMat4.elements[1] *= invSX;
291
+ tmpMat4.elements[2] *= invSX;
292
+ tmpMat4.elements[4] *= invSY;
293
+ tmpMat4.elements[5] *= invSY;
294
+ tmpMat4.elements[6] *= invSY;
295
+ tmpMat4.elements[8] *= invSZ;
296
+ tmpMat4.elements[9] *= invSZ;
297
+ tmpMat4.elements[10] *= invSZ;
298
+ quaternion.setRotationMatrix(tmpMat4);
299
+ scale.set(sx, sy, sz);
300
+ return this;
301
+ }
302
+ transpose() {
303
+ const te = this.elements;
304
+ let tmp;
305
+ tmp = te[1];
306
+ te[1] = te[4];
307
+ te[4] = tmp;
308
+ tmp = te[2];
309
+ te[2] = te[8];
310
+ te[8] = tmp;
311
+ tmp = te[6];
312
+ te[6] = te[9];
313
+ te[9] = tmp;
314
+ tmp = te[3];
315
+ te[3] = te[12];
316
+ te[12] = tmp;
317
+ tmp = te[7];
318
+ te[7] = te[13];
319
+ te[13] = tmp;
320
+ tmp = te[11];
321
+ te[11] = te[14];
322
+ te[14] = tmp;
323
+ return this;
324
+ }
325
+ }
326
+ export class Matrix3 {
327
+ constructor() {
328
+ this.elements = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
329
+ }
330
+ set(n11, n12, n13, n21, n22, n23, n31, n32, n33) {
331
+ const te = this.elements;
332
+ te[0] = n11;
333
+ te[1] = n21;
334
+ te[2] = n31;
335
+ te[3] = n12;
336
+ te[4] = n22;
337
+ te[5] = n32;
338
+ te[6] = n13;
339
+ te[7] = n23;
340
+ te[8] = n33;
341
+ return this;
342
+ }
343
+ setFromMatrix4(m) {
344
+ const me = m.elements;
345
+ this.set(me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10]);
346
+ return this;
347
+ }
348
+ }
349
+ const tmpVec = new Vector3(0, 0, 0);
350
+ const tmpMat4 = new Matrix4();