xl-public-utils 1.0.10 → 1.0.12

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.
@@ -0,0 +1,863 @@
1
+ import { Vector3 } from './Vector3.js';
2
+
3
+ class Matrix4 {
4
+ constructor() {
5
+ this.isMatrix4 = true;
6
+
7
+ this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
8
+
9
+ if (arguments.length > 0) {
10
+ console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');
11
+ }
12
+ }
13
+
14
+ set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
15
+ const te = this.elements;
16
+
17
+ te[0] = n11;
18
+ te[4] = n12;
19
+ te[8] = n13;
20
+ te[12] = n14;
21
+ te[1] = n21;
22
+ te[5] = n22;
23
+ te[9] = n23;
24
+ te[13] = n24;
25
+ te[2] = n31;
26
+ te[6] = n32;
27
+ te[10] = n33;
28
+ te[14] = n34;
29
+ te[3] = n41;
30
+ te[7] = n42;
31
+ te[11] = n43;
32
+ te[15] = n44;
33
+
34
+ return this;
35
+ }
36
+
37
+ identity() {
38
+ this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
39
+
40
+ return this;
41
+ }
42
+
43
+ clone() {
44
+ return new Matrix4().fromArray(this.elements);
45
+ }
46
+
47
+ copy(m) {
48
+ const te = this.elements;
49
+ const me = m.elements;
50
+
51
+ te[0] = me[0];
52
+ te[1] = me[1];
53
+ te[2] = me[2];
54
+ te[3] = me[3];
55
+ te[4] = me[4];
56
+ te[5] = me[5];
57
+ te[6] = me[6];
58
+ te[7] = me[7];
59
+ te[8] = me[8];
60
+ te[9] = me[9];
61
+ te[10] = me[10];
62
+ te[11] = me[11];
63
+ te[12] = me[12];
64
+ te[13] = me[13];
65
+ te[14] = me[14];
66
+ te[15] = me[15];
67
+
68
+ return this;
69
+ }
70
+
71
+ copyPosition(m) {
72
+ const te = this.elements,
73
+ me = m.elements;
74
+
75
+ te[12] = me[12];
76
+ te[13] = me[13];
77
+ te[14] = me[14];
78
+
79
+ return this;
80
+ }
81
+
82
+ setFromMatrix3(m) {
83
+ const me = m.elements;
84
+
85
+ this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1);
86
+
87
+ return this;
88
+ }
89
+
90
+ extractBasis(xAxis, yAxis, zAxis) {
91
+ xAxis.setFromMatrixColumn(this, 0);
92
+ yAxis.setFromMatrixColumn(this, 1);
93
+ zAxis.setFromMatrixColumn(this, 2);
94
+
95
+ return this;
96
+ }
97
+
98
+ makeBasis(xAxis, yAxis, zAxis) {
99
+ this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1);
100
+
101
+ return this;
102
+ }
103
+
104
+ extractRotation(m) {
105
+ // this method does not support reflection matrices
106
+
107
+ const te = this.elements;
108
+ const me = m.elements;
109
+
110
+ const scaleX = 1 / _v1.setFromMatrixColumn(m, 0).length();
111
+ const scaleY = 1 / _v1.setFromMatrixColumn(m, 1).length();
112
+ const scaleZ = 1 / _v1.setFromMatrixColumn(m, 2).length();
113
+
114
+ te[0] = me[0] * scaleX;
115
+ te[1] = me[1] * scaleX;
116
+ te[2] = me[2] * scaleX;
117
+ te[3] = 0;
118
+
119
+ te[4] = me[4] * scaleY;
120
+ te[5] = me[5] * scaleY;
121
+ te[6] = me[6] * scaleY;
122
+ te[7] = 0;
123
+
124
+ te[8] = me[8] * scaleZ;
125
+ te[9] = me[9] * scaleZ;
126
+ te[10] = me[10] * scaleZ;
127
+ te[11] = 0;
128
+
129
+ te[12] = 0;
130
+ te[13] = 0;
131
+ te[14] = 0;
132
+ te[15] = 1;
133
+
134
+ return this;
135
+ }
136
+
137
+ makeRotationFromEuler(euler) {
138
+ if (!(euler && euler.isEuler)) {
139
+ console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');
140
+ }
141
+
142
+ const te = this.elements;
143
+
144
+ const x = euler.x,
145
+ y = euler.y,
146
+ z = euler.z;
147
+ const a = Math.cos(x),
148
+ b = Math.sin(x);
149
+ const c = Math.cos(y),
150
+ d = Math.sin(y);
151
+ const e = Math.cos(z),
152
+ f = Math.sin(z);
153
+
154
+ if (euler.order === 'XYZ') {
155
+ const ae = a * e,
156
+ af = a * f,
157
+ be = b * e,
158
+ bf = b * f;
159
+
160
+ te[0] = c * e;
161
+ te[4] = -c * f;
162
+ te[8] = d;
163
+
164
+ te[1] = af + be * d;
165
+ te[5] = ae - bf * d;
166
+ te[9] = -b * c;
167
+
168
+ te[2] = bf - ae * d;
169
+ te[6] = be + af * d;
170
+ te[10] = a * c;
171
+ } else if (euler.order === 'YXZ') {
172
+ const ce = c * e,
173
+ cf = c * f,
174
+ de = d * e,
175
+ df = d * f;
176
+
177
+ te[0] = ce + df * b;
178
+ te[4] = de * b - cf;
179
+ te[8] = a * d;
180
+
181
+ te[1] = a * f;
182
+ te[5] = a * e;
183
+ te[9] = -b;
184
+
185
+ te[2] = cf * b - de;
186
+ te[6] = df + ce * b;
187
+ te[10] = a * c;
188
+ } else if (euler.order === 'ZXY') {
189
+ const ce = c * e,
190
+ cf = c * f,
191
+ de = d * e,
192
+ df = d * f;
193
+
194
+ te[0] = ce - df * b;
195
+ te[4] = -a * f;
196
+ te[8] = de + cf * b;
197
+
198
+ te[1] = cf + de * b;
199
+ te[5] = a * e;
200
+ te[9] = df - ce * b;
201
+
202
+ te[2] = -a * d;
203
+ te[6] = b;
204
+ te[10] = a * c;
205
+ } else if (euler.order === 'ZYX') {
206
+ const ae = a * e,
207
+ af = a * f,
208
+ be = b * e,
209
+ bf = b * f;
210
+
211
+ te[0] = c * e;
212
+ te[4] = be * d - af;
213
+ te[8] = ae * d + bf;
214
+
215
+ te[1] = c * f;
216
+ te[5] = bf * d + ae;
217
+ te[9] = af * d - be;
218
+
219
+ te[2] = -d;
220
+ te[6] = b * c;
221
+ te[10] = a * c;
222
+ } else if (euler.order === 'YZX') {
223
+ const ac = a * c,
224
+ ad = a * d,
225
+ bc = b * c,
226
+ bd = b * d;
227
+
228
+ te[0] = c * e;
229
+ te[4] = bd - ac * f;
230
+ te[8] = bc * f + ad;
231
+
232
+ te[1] = f;
233
+ te[5] = a * e;
234
+ te[9] = -b * e;
235
+
236
+ te[2] = -d * e;
237
+ te[6] = ad * f + bc;
238
+ te[10] = ac - bd * f;
239
+ } else if (euler.order === 'XZY') {
240
+ const ac = a * c,
241
+ ad = a * d,
242
+ bc = b * c,
243
+ bd = b * d;
244
+
245
+ te[0] = c * e;
246
+ te[4] = -f;
247
+ te[8] = d * e;
248
+
249
+ te[1] = ac * f + bd;
250
+ te[5] = a * e;
251
+ te[9] = ad * f - bc;
252
+
253
+ te[2] = bc * f - ad;
254
+ te[6] = b * e;
255
+ te[10] = bd * f + ac;
256
+ }
257
+
258
+ // bottom row
259
+ te[3] = 0;
260
+ te[7] = 0;
261
+ te[11] = 0;
262
+
263
+ // last column
264
+ te[12] = 0;
265
+ te[13] = 0;
266
+ te[14] = 0;
267
+ te[15] = 1;
268
+
269
+ return this;
270
+ }
271
+
272
+ makeRotationFromQuaternion(q) {
273
+ return this.compose(_zero, q, _one);
274
+ }
275
+
276
+ lookAt(eye, target, up) {
277
+ const te = this.elements;
278
+
279
+ _z.subVectors(eye, target);
280
+
281
+ if (_z.lengthSq() === 0) {
282
+ // eye and target are in the same position
283
+
284
+ _z.z = 1;
285
+ }
286
+
287
+ _z.normalize();
288
+ _x.crossVectors(up, _z);
289
+
290
+ if (_x.lengthSq() === 0) {
291
+ // up and z are parallel
292
+
293
+ if (Math.abs(up.z) === 1) {
294
+ _z.x += 0.0001;
295
+ } else {
296
+ _z.z += 0.0001;
297
+ }
298
+
299
+ _z.normalize();
300
+ _x.crossVectors(up, _z);
301
+ }
302
+
303
+ _x.normalize();
304
+ _y.crossVectors(_z, _x);
305
+
306
+ te[0] = _x.x;
307
+ te[4] = _y.x;
308
+ te[8] = _z.x;
309
+ te[1] = _x.y;
310
+ te[5] = _y.y;
311
+ te[9] = _z.y;
312
+ te[2] = _x.z;
313
+ te[6] = _y.z;
314
+ te[10] = _z.z;
315
+
316
+ return this;
317
+ }
318
+
319
+ multiply(m, n) {
320
+ if (n !== undefined) {
321
+ console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');
322
+ return this.multiplyMatrices(m, n);
323
+ }
324
+
325
+ return this.multiplyMatrices(this, m);
326
+ }
327
+
328
+ premultiply(m) {
329
+ return this.multiplyMatrices(m, this);
330
+ }
331
+
332
+ multiplyMatrices(a, b) {
333
+ const ae = a.elements;
334
+ const be = b.elements;
335
+ const te = this.elements;
336
+
337
+ const a11 = ae[0],
338
+ a12 = ae[4],
339
+ a13 = ae[8],
340
+ a14 = ae[12];
341
+ const a21 = ae[1],
342
+ a22 = ae[5],
343
+ a23 = ae[9],
344
+ a24 = ae[13];
345
+ const a31 = ae[2],
346
+ a32 = ae[6],
347
+ a33 = ae[10],
348
+ a34 = ae[14];
349
+ const a41 = ae[3],
350
+ a42 = ae[7],
351
+ a43 = ae[11],
352
+ a44 = ae[15];
353
+
354
+ const b11 = be[0],
355
+ b12 = be[4],
356
+ b13 = be[8],
357
+ b14 = be[12];
358
+ const b21 = be[1],
359
+ b22 = be[5],
360
+ b23 = be[9],
361
+ b24 = be[13];
362
+ const b31 = be[2],
363
+ b32 = be[6],
364
+ b33 = be[10],
365
+ b34 = be[14];
366
+ const b41 = be[3],
367
+ b42 = be[7],
368
+ b43 = be[11],
369
+ b44 = be[15];
370
+
371
+ te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
372
+ te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
373
+ te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
374
+ te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
375
+
376
+ te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
377
+ te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
378
+ te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
379
+ te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
380
+
381
+ te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
382
+ te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
383
+ te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
384
+ te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
385
+
386
+ te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
387
+ te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
388
+ te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
389
+ te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
390
+
391
+ return this;
392
+ }
393
+
394
+ multiplyScalar(s) {
395
+ const te = this.elements;
396
+
397
+ te[0] *= s;
398
+ te[4] *= s;
399
+ te[8] *= s;
400
+ te[12] *= s;
401
+ te[1] *= s;
402
+ te[5] *= s;
403
+ te[9] *= s;
404
+ te[13] *= s;
405
+ te[2] *= s;
406
+ te[6] *= s;
407
+ te[10] *= s;
408
+ te[14] *= s;
409
+ te[3] *= s;
410
+ te[7] *= s;
411
+ te[11] *= s;
412
+ te[15] *= s;
413
+
414
+ return this;
415
+ }
416
+
417
+ determinant() {
418
+ const te = this.elements;
419
+
420
+ const n11 = te[0],
421
+ n12 = te[4],
422
+ n13 = te[8],
423
+ n14 = te[12];
424
+ const n21 = te[1],
425
+ n22 = te[5],
426
+ n23 = te[9],
427
+ n24 = te[13];
428
+ const n31 = te[2],
429
+ n32 = te[6],
430
+ n33 = te[10],
431
+ n34 = te[14];
432
+ const n41 = te[3],
433
+ n42 = te[7],
434
+ n43 = te[11],
435
+ n44 = te[15];
436
+
437
+ //TODO: make this more efficient
438
+ //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
439
+
440
+ return (
441
+ n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) +
442
+ n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) +
443
+ n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) +
444
+ n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31)
445
+ );
446
+ }
447
+
448
+ transpose() {
449
+ const te = this.elements;
450
+ let tmp;
451
+
452
+ tmp = te[1];
453
+ te[1] = te[4];
454
+ te[4] = tmp;
455
+ tmp = te[2];
456
+ te[2] = te[8];
457
+ te[8] = tmp;
458
+ tmp = te[6];
459
+ te[6] = te[9];
460
+ te[9] = tmp;
461
+
462
+ tmp = te[3];
463
+ te[3] = te[12];
464
+ te[12] = tmp;
465
+ tmp = te[7];
466
+ te[7] = te[13];
467
+ te[13] = tmp;
468
+ tmp = te[11];
469
+ te[11] = te[14];
470
+ te[14] = tmp;
471
+
472
+ return this;
473
+ }
474
+
475
+ setPosition(x, y, z) {
476
+ const te = this.elements;
477
+
478
+ if (x.isVector3) {
479
+ te[12] = x.x;
480
+ te[13] = x.y;
481
+ te[14] = x.z;
482
+ } else {
483
+ te[12] = x;
484
+ te[13] = y;
485
+ te[14] = z;
486
+ }
487
+
488
+ return this;
489
+ }
490
+
491
+ invert() {
492
+ // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
493
+ const te = this.elements,
494
+ n11 = te[0],
495
+ n21 = te[1],
496
+ n31 = te[2],
497
+ n41 = te[3],
498
+ n12 = te[4],
499
+ n22 = te[5],
500
+ n32 = te[6],
501
+ n42 = te[7],
502
+ n13 = te[8],
503
+ n23 = te[9],
504
+ n33 = te[10],
505
+ n43 = te[11],
506
+ n14 = te[12],
507
+ n24 = te[13],
508
+ n34 = te[14],
509
+ n44 = te[15],
510
+ t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
511
+ t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
512
+ t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
513
+ t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
514
+
515
+ const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
516
+
517
+ if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
518
+
519
+ const detInv = 1 / det;
520
+
521
+ te[0] = t11 * detInv;
522
+ te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv;
523
+ te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv;
524
+ te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv;
525
+
526
+ te[4] = t12 * detInv;
527
+ te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv;
528
+ te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv;
529
+ te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv;
530
+
531
+ te[8] = t13 * detInv;
532
+ te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv;
533
+ te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv;
534
+ te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv;
535
+
536
+ te[12] = t14 * detInv;
537
+ te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv;
538
+ te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv;
539
+ te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv;
540
+
541
+ return this;
542
+ }
543
+
544
+ scale(v) {
545
+ const te = this.elements;
546
+ const x = v.x,
547
+ y = v.y,
548
+ z = v.z;
549
+
550
+ te[0] *= x;
551
+ te[4] *= y;
552
+ te[8] *= z;
553
+ te[1] *= x;
554
+ te[5] *= y;
555
+ te[9] *= z;
556
+ te[2] *= x;
557
+ te[6] *= y;
558
+ te[10] *= z;
559
+ te[3] *= x;
560
+ te[7] *= y;
561
+ te[11] *= z;
562
+
563
+ return this;
564
+ }
565
+
566
+ getMaxScaleOnAxis() {
567
+ const te = this.elements;
568
+
569
+ const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2];
570
+ const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6];
571
+ const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10];
572
+
573
+ return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq));
574
+ }
575
+
576
+ makeTranslation(x, y, z) {
577
+ this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1);
578
+
579
+ return this;
580
+ }
581
+
582
+ makeRotationX(theta) {
583
+ const c = Math.cos(theta),
584
+ s = Math.sin(theta);
585
+
586
+ this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
587
+
588
+ return this;
589
+ }
590
+
591
+ makeRotationY(theta) {
592
+ const c = Math.cos(theta),
593
+ s = Math.sin(theta);
594
+
595
+ this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
596
+
597
+ return this;
598
+ }
599
+
600
+ makeRotationZ(theta) {
601
+ const c = Math.cos(theta),
602
+ s = Math.sin(theta);
603
+
604
+ this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
605
+
606
+ return this;
607
+ }
608
+
609
+ makeRotationAxis(axis, angle) {
610
+ // Based on http://www.gamedev.net/reference/articles/article1199.asp
611
+
612
+ const c = Math.cos(angle);
613
+ const s = Math.sin(angle);
614
+ const t = 1 - c;
615
+ const x = axis.x,
616
+ y = axis.y,
617
+ z = axis.z;
618
+ const tx = t * x,
619
+ ty = t * y;
620
+
621
+ this.set(
622
+ tx * x + c,
623
+ tx * y - s * z,
624
+ tx * z + s * y,
625
+ 0,
626
+ tx * y + s * z,
627
+ ty * y + c,
628
+ ty * z - s * x,
629
+ 0,
630
+ tx * z - s * y,
631
+ ty * z + s * x,
632
+ t * z * z + c,
633
+ 0,
634
+ 0,
635
+ 0,
636
+ 0,
637
+ 1,
638
+ );
639
+
640
+ return this;
641
+ }
642
+
643
+ makeScale(x, y, z) {
644
+ this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
645
+
646
+ return this;
647
+ }
648
+
649
+ makeShear(xy, xz, yx, yz, zx, zy) {
650
+ this.set(1, yx, zx, 0, xy, 1, zy, 0, xz, yz, 1, 0, 0, 0, 0, 1);
651
+
652
+ return this;
653
+ }
654
+
655
+ compose(position, quaternion, scale) {
656
+ const te = this.elements;
657
+
658
+ const x = quaternion._x,
659
+ y = quaternion._y,
660
+ z = quaternion._z,
661
+ w = quaternion._w;
662
+ const x2 = x + x,
663
+ y2 = y + y,
664
+ z2 = z + z;
665
+ const xx = x * x2,
666
+ xy = x * y2,
667
+ xz = x * z2;
668
+ const yy = y * y2,
669
+ yz = y * z2,
670
+ zz = z * z2;
671
+ const wx = w * x2,
672
+ wy = w * y2,
673
+ wz = w * z2;
674
+
675
+ const sx = scale.x,
676
+ sy = scale.y,
677
+ sz = scale.z;
678
+
679
+ te[0] = (1 - (yy + zz)) * sx;
680
+ te[1] = (xy + wz) * sx;
681
+ te[2] = (xz - wy) * sx;
682
+ te[3] = 0;
683
+
684
+ te[4] = (xy - wz) * sy;
685
+ te[5] = (1 - (xx + zz)) * sy;
686
+ te[6] = (yz + wx) * sy;
687
+ te[7] = 0;
688
+
689
+ te[8] = (xz + wy) * sz;
690
+ te[9] = (yz - wx) * sz;
691
+ te[10] = (1 - (xx + yy)) * sz;
692
+ te[11] = 0;
693
+
694
+ te[12] = position.x;
695
+ te[13] = position.y;
696
+ te[14] = position.z;
697
+ te[15] = 1;
698
+
699
+ return this;
700
+ }
701
+
702
+ decompose(position, quaternion, scale) {
703
+ const te = this.elements;
704
+
705
+ let sx = _v1.set(te[0], te[1], te[2]).length();
706
+ const sy = _v1.set(te[4], te[5], te[6]).length();
707
+ const sz = _v1.set(te[8], te[9], te[10]).length();
708
+
709
+ // if determine is negative, we need to invert one scale
710
+ const det = this.determinant();
711
+ if (det < 0) sx = -sx;
712
+
713
+ position.x = te[12];
714
+ position.y = te[13];
715
+ position.z = te[14];
716
+
717
+ // scale the rotation part
718
+ _m1.copy(this);
719
+
720
+ const invSX = 1 / sx;
721
+ const invSY = 1 / sy;
722
+ const invSZ = 1 / sz;
723
+
724
+ _m1.elements[0] *= invSX;
725
+ _m1.elements[1] *= invSX;
726
+ _m1.elements[2] *= invSX;
727
+
728
+ _m1.elements[4] *= invSY;
729
+ _m1.elements[5] *= invSY;
730
+ _m1.elements[6] *= invSY;
731
+
732
+ _m1.elements[8] *= invSZ;
733
+ _m1.elements[9] *= invSZ;
734
+ _m1.elements[10] *= invSZ;
735
+
736
+ quaternion.setFromRotationMatrix(_m1);
737
+
738
+ scale.x = sx;
739
+ scale.y = sy;
740
+ scale.z = sz;
741
+
742
+ return this;
743
+ }
744
+
745
+ makePerspective(left, right, top, bottom, near, far) {
746
+ if (far === undefined) {
747
+ console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');
748
+ }
749
+
750
+ const te = this.elements;
751
+ const x = (2 * near) / (right - left);
752
+ const y = (2 * near) / (top - bottom);
753
+
754
+ const a = (right + left) / (right - left);
755
+ const b = (top + bottom) / (top - bottom);
756
+ const c = -(far + near) / (far - near);
757
+ const d = (-2 * far * near) / (far - near);
758
+
759
+ te[0] = x;
760
+ te[4] = 0;
761
+ te[8] = a;
762
+ te[12] = 0;
763
+ te[1] = 0;
764
+ te[5] = y;
765
+ te[9] = b;
766
+ te[13] = 0;
767
+ te[2] = 0;
768
+ te[6] = 0;
769
+ te[10] = c;
770
+ te[14] = d;
771
+ te[3] = 0;
772
+ te[7] = 0;
773
+ te[11] = -1;
774
+ te[15] = 0;
775
+
776
+ return this;
777
+ }
778
+
779
+ makeOrthographic(left, right, top, bottom, near, far) {
780
+ const te = this.elements;
781
+ const w = 1.0 / (right - left);
782
+ const h = 1.0 / (top - bottom);
783
+ const p = 1.0 / (far - near);
784
+
785
+ const x = (right + left) * w;
786
+ const y = (top + bottom) * h;
787
+ const z = (far + near) * p;
788
+
789
+ te[0] = 2 * w;
790
+ te[4] = 0;
791
+ te[8] = 0;
792
+ te[12] = -x;
793
+ te[1] = 0;
794
+ te[5] = 2 * h;
795
+ te[9] = 0;
796
+ te[13] = -y;
797
+ te[2] = 0;
798
+ te[6] = 0;
799
+ te[10] = -2 * p;
800
+ te[14] = -z;
801
+ te[3] = 0;
802
+ te[7] = 0;
803
+ te[11] = 0;
804
+ te[15] = 1;
805
+
806
+ return this;
807
+ }
808
+
809
+ equals(matrix) {
810
+ const te = this.elements;
811
+ const me = matrix.elements;
812
+
813
+ for (let i = 0; i < 16; i++) {
814
+ if (te[i] !== me[i]) return false;
815
+ }
816
+
817
+ return true;
818
+ }
819
+
820
+ fromArray(array, offset = 0) {
821
+ for (let i = 0; i < 16; i++) {
822
+ this.elements[i] = array[i + offset];
823
+ }
824
+
825
+ return this;
826
+ }
827
+
828
+ toArray(array = [], offset = 0) {
829
+ const te = this.elements;
830
+
831
+ array[offset] = te[0];
832
+ array[offset + 1] = te[1];
833
+ array[offset + 2] = te[2];
834
+ array[offset + 3] = te[3];
835
+
836
+ array[offset + 4] = te[4];
837
+ array[offset + 5] = te[5];
838
+ array[offset + 6] = te[6];
839
+ array[offset + 7] = te[7];
840
+
841
+ array[offset + 8] = te[8];
842
+ array[offset + 9] = te[9];
843
+ array[offset + 10] = te[10];
844
+ array[offset + 11] = te[11];
845
+
846
+ array[offset + 12] = te[12];
847
+ array[offset + 13] = te[13];
848
+ array[offset + 14] = te[14];
849
+ array[offset + 15] = te[15];
850
+
851
+ return array;
852
+ }
853
+ }
854
+
855
+ const _v1 = /*@__PURE__*/ new Vector3();
856
+ const _m1 = /*@__PURE__*/ new Matrix4();
857
+ const _zero = /*@__PURE__*/ new Vector3(0, 0, 0);
858
+ const _one = /*@__PURE__*/ new Vector3(1, 1, 1);
859
+ const _x = /*@__PURE__*/ new Vector3();
860
+ const _y = /*@__PURE__*/ new Vector3();
861
+ const _z = /*@__PURE__*/ new Vector3();
862
+
863
+ export { Matrix4 };