@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.
- package/CHANGELOG.md +124 -113
- package/README.md +39 -39
- package/THIRD_PARTY_LICENSES.txt +1373 -1373
- package/bin/cli.js +125 -118
- package/dist/SplatData.d.ts +67 -67
- package/dist/SplatData.js +167 -150
- package/dist/constant.d.ts +3 -3
- package/dist/constant.js +13 -13
- package/dist/file/IFile.d.ts +5 -5
- package/dist/file/IFile.js +1 -1
- package/dist/file/esz.d.ts +11 -11
- package/dist/file/esz.js +337 -322
- package/dist/file/index.d.ts +8 -8
- package/dist/file/index.js +7 -7
- package/dist/file/ksplat.d.ts +12 -12
- package/dist/file/ksplat.js +293 -231
- package/dist/file/lcc.d.ts +11 -11
- package/dist/file/lcc.js +161 -158
- package/dist/file/ply.d.ts +13 -13
- package/dist/file/ply.js +439 -390
- package/dist/file/sog.d.ts +80 -80
- package/dist/file/sog.js +525 -494
- package/dist/file/splat.d.ts +6 -6
- package/dist/file/splat.js +119 -99
- package/dist/file/spz.d.ts +11 -11
- package/dist/file/spz.js +597 -583
- package/dist/file/voxel.d.ts +43 -37
- package/dist/file/voxel.js +411 -280
- package/dist/index.d.ts +33 -33
- package/dist/index.js +54 -54
- package/dist/native/index.d.ts +54 -54
- package/dist/native/index.js +122 -129
- package/dist/native/utils.d.ts +1 -0
- package/dist/native/utils.js +54 -0
- package/dist/tasks/AutoChunkLodTask.d.ts +13 -13
- package/dist/tasks/AutoChunkLodTask.js +117 -117
- package/dist/tasks/AutoLodTask.d.ts +10 -10
- package/dist/tasks/AutoLodTask.js +20 -20
- package/dist/tasks/BaseTask.d.ts +15 -15
- package/dist/tasks/BaseTask.js +5 -5
- package/dist/tasks/FlexLodTask.d.ts +12 -12
- package/dist/tasks/FlexLodTask.js +54 -44
- package/dist/tasks/ModifyTask.d.ts +9 -9
- package/dist/tasks/ModifyTask.js +166 -156
- package/dist/tasks/ReadTask.d.ts +9 -9
- package/dist/tasks/ReadTask.js +29 -29
- package/dist/tasks/SkeletonLodTask.d.ts +10 -10
- package/dist/tasks/SkeletonLodTask.js +176 -156
- package/dist/tasks/VoxelTask.d.ts +35 -30
- package/dist/tasks/VoxelTask.js +40 -37
- package/dist/tasks/WriteTask.d.ts +12 -12
- package/dist/tasks/WriteTask.js +70 -70
- package/dist/utils/BufferReader.d.ts +12 -12
- package/dist/utils/BufferReader.js +45 -45
- package/dist/utils/Logger.d.ts +11 -11
- package/dist/utils/Logger.js +40 -40
- package/dist/utils/StreamChunkDecoder.d.ts +16 -16
- package/dist/utils/StreamChunkDecoder.js +31 -31
- package/dist/utils/index.d.ts +27 -27
- package/dist/utils/index.js +101 -101
- package/dist/utils/k-means.d.ts +4 -4
- package/dist/utils/k-means.js +340 -341
- package/dist/utils/math.d.ts +46 -46
- package/dist/utils/math.js +350 -346
- package/dist/utils/quantize-1d.d.ts +4 -4
- package/dist/utils/quantize-1d.js +164 -164
- package/dist/utils/sh-rotate.d.ts +2 -2
- package/dist/utils/sh-rotate.js +236 -175
- package/dist/utils/splat.d.ts +21 -21
- package/dist/utils/splat.js +397 -387
- package/dist/utils/voxel/binary.d.ts +8 -0
- package/dist/utils/voxel/binary.js +176 -0
- package/dist/utils/voxel/common.d.ts +178 -162
- package/dist/utils/voxel/common.js +1752 -1682
- package/dist/utils/voxel/coplanar-merge.d.ts +63 -63
- package/dist/utils/voxel/coplanar-merge.js +818 -819
- package/dist/utils/voxel/filter-cluster.d.ts +20 -0
- package/dist/utils/voxel/filter-cluster.js +628 -0
- package/dist/utils/voxel/gpu-dilation.d.ts +2 -2
- package/dist/utils/voxel/gpu-dilation.js +677 -656
- package/dist/utils/voxel/marching-cubes.d.ts +42 -42
- package/dist/utils/voxel/marching-cubes.js +1645 -1657
- package/dist/utils/voxel/mesh.d.ts +3 -3
- package/dist/utils/voxel/mesh.js +130 -130
- package/dist/utils/voxel/nav.d.ts +29 -29
- package/dist/utils/voxel/nav.js +1068 -1043
- package/dist/utils/voxel/postprocess.d.ts +23 -23
- package/dist/utils/voxel/postprocess.js +408 -375
- package/dist/utils/voxel/voxel-faces.d.ts +18 -18
- package/dist/utils/voxel/voxel-faces.js +662 -663
- package/dist/utils/voxel/voxelize.d.ts +34 -33
- package/dist/utils/voxel/voxelize.js +1208 -1193
- package/dist/utils/webgpu.d.ts +8 -8
- package/dist/utils/webgpu.js +122 -122
- package/package.json +38 -39
- package/dist/native/cpp/bin/linux/binding.node +0 -0
- package/dist/native/cpp/bin/windows/binding.node +0 -0
package/dist/utils/math.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
+
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
+
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
const
|
|
207
|
-
const
|
|
208
|
-
const
|
|
209
|
-
const
|
|
210
|
-
const
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
const
|
|
217
|
-
const
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
const
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
te[
|
|
237
|
-
te[
|
|
238
|
-
te[
|
|
239
|
-
te[
|
|
240
|
-
te[
|
|
241
|
-
te[
|
|
242
|
-
te[
|
|
243
|
-
te[
|
|
244
|
-
te[
|
|
245
|
-
te[
|
|
246
|
-
te[
|
|
247
|
-
te[
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
te
|
|
256
|
-
|
|
257
|
-
te[
|
|
258
|
-
te[
|
|
259
|
-
te[
|
|
260
|
-
te[
|
|
261
|
-
te[
|
|
262
|
-
te[
|
|
263
|
-
te[
|
|
264
|
-
te[
|
|
265
|
-
te[
|
|
266
|
-
te[
|
|
267
|
-
te[
|
|
268
|
-
te[
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
tmpMat4.elements
|
|
289
|
-
tmpMat4.elements[
|
|
290
|
-
tmpMat4.elements[
|
|
291
|
-
tmpMat4.elements[
|
|
292
|
-
tmpMat4.elements[
|
|
293
|
-
tmpMat4.elements[
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
te
|
|
304
|
-
tmp
|
|
305
|
-
|
|
306
|
-
te[
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
te[
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
te[
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
te[
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
te[
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
te
|
|
332
|
-
te[
|
|
333
|
-
te[
|
|
334
|
-
te[
|
|
335
|
-
te[
|
|
336
|
-
te[
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
this
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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();
|