@manycore/aholo-splat-transform 1.2.7 → 1.2.9

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