@vertexvis/geometry 1.0.2-canary.0 → 1.0.2-canary.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/dist/bundle.cjs +259 -244
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.js +259 -242
- package/dist/bundle.js.map +1 -1
- package/dist/cdn/bundle.js +259 -242
- package/dist/cdn/bundle.js.map +1 -1
- package/dist/cdn/bundle.min.js +1 -1
- package/dist/cdn/bundle.min.js.map +1 -1
- package/dist/euler.d.ts +1 -1
- package/dist/matrix4.d.ts +33 -25
- package/dist/vector3.d.ts +17 -1
- package/package.json +4 -4
package/dist/bundle.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var tslib = require('tslib');
|
|
6
4
|
|
|
7
5
|
/**
|
|
@@ -176,21 +174,21 @@ function fromJson$5(json) {
|
|
|
176
174
|
|
|
177
175
|
var point = /*#__PURE__*/Object.freeze({
|
|
178
176
|
__proto__: null,
|
|
177
|
+
add: add$1,
|
|
179
178
|
create: create$d,
|
|
180
|
-
polar: polar,
|
|
181
179
|
distance: distance$2,
|
|
182
|
-
|
|
183
|
-
add: add$1,
|
|
180
|
+
fromJson: fromJson$5,
|
|
184
181
|
isEqual: isEqual$3,
|
|
185
182
|
lerp: lerp$1,
|
|
186
|
-
negate: negate$1,
|
|
187
|
-
scale: scale$5,
|
|
188
|
-
scaleProportional: scaleProportional,
|
|
189
183
|
magnitude: magnitude$2,
|
|
190
|
-
|
|
184
|
+
negate: negate$1,
|
|
191
185
|
normalDirectionVector: normalDirectionVector,
|
|
186
|
+
normalizeVector: normalizeVector,
|
|
192
187
|
orthogonalVector: orthogonalVector,
|
|
193
|
-
|
|
188
|
+
polar: polar,
|
|
189
|
+
scale: scale$5,
|
|
190
|
+
scaleProportional: scaleProportional,
|
|
191
|
+
subtract: subtract$1
|
|
194
192
|
});
|
|
195
193
|
|
|
196
194
|
/**
|
|
@@ -261,10 +259,10 @@ function fromValues(
|
|
|
261
259
|
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
|
262
260
|
/* eslint-disable prettier/prettier */
|
|
263
261
|
return [
|
|
264
|
-
m11,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
262
|
+
m11, m12, m13, m14,
|
|
263
|
+
m21, m22, m23, m24,
|
|
264
|
+
m31, m32, m33, m34,
|
|
265
|
+
m41, m42, m43, m44,
|
|
268
266
|
];
|
|
269
267
|
/* eslint-enable prettier/prettier */
|
|
270
268
|
}
|
|
@@ -334,9 +332,9 @@ function makeRotation(rotation) {
|
|
|
334
332
|
var wx = w * x2, wy = w * y2, wz = w * z2;
|
|
335
333
|
/* eslint-disable prettier/prettier */
|
|
336
334
|
return [
|
|
337
|
-
1 - (yy + zz), xy
|
|
338
|
-
xy
|
|
339
|
-
xz
|
|
335
|
+
1 - (yy + zz), xy - wz, xz + wy, 0,
|
|
336
|
+
xy + wz, 1 - (xx + zz), yz - wx, 0,
|
|
337
|
+
xz - wy, yz + wx, 1 - (xx + yy), 0,
|
|
340
338
|
0, 0, 0, 1
|
|
341
339
|
];
|
|
342
340
|
/* eslint-enable prettier/prettier */
|
|
@@ -366,33 +364,33 @@ function makeScale(scale) {
|
|
|
366
364
|
/* eslint-enable prettier/prettier */
|
|
367
365
|
}
|
|
368
366
|
/**
|
|
369
|
-
* Creates a matrix that has translation, rotation and scale applied to it.
|
|
367
|
+
* Creates a matrix that has translation, rotation, and scale applied to it.
|
|
370
368
|
*
|
|
371
369
|
* @param translation The translation applied to the matrix.
|
|
372
370
|
* @param rotation The rotation applied to the matrix.
|
|
373
371
|
* @param scale The scale applied to the matrix.
|
|
374
|
-
* @returns A transformed matrix.
|
|
372
|
+
* @returns A transformed matrix in column-major form.
|
|
375
373
|
*/
|
|
376
374
|
function makeTRS(translation, rotation, scale) {
|
|
377
375
|
var t = makeTranslation(translation);
|
|
378
|
-
var r = makeRotation(rotation);
|
|
376
|
+
var r = transpose(makeRotation(rotation));
|
|
379
377
|
var s = makeScale(scale);
|
|
380
|
-
return multiply$2(multiply$2(
|
|
378
|
+
return multiply$2(s, multiply$2(r, t));
|
|
381
379
|
}
|
|
382
380
|
/**
|
|
383
381
|
* Returns a matrix that has the basis components (upper left 3x3 matrix) set to
|
|
384
382
|
* the following x, y, and z axis.
|
|
385
383
|
*
|
|
386
384
|
* ```
|
|
387
|
-
* x.x y.
|
|
388
|
-
* x.y y.
|
|
389
|
-
* x.
|
|
385
|
+
* x.x x.y x.z 0
|
|
386
|
+
* y.x y.y y.z 0
|
|
387
|
+
* z.x z.y z.z 0
|
|
390
388
|
* 0 0 0 0
|
|
391
389
|
* ```
|
|
392
390
|
*
|
|
393
|
-
* @param x The x
|
|
394
|
-
* @param y The y
|
|
395
|
-
* @param z The z
|
|
391
|
+
* @param x The x-axis to set.
|
|
392
|
+
* @param y The y-axis to set.
|
|
393
|
+
* @param z The z-axis to set.
|
|
396
394
|
* @returns A matrix with its basis components populated.
|
|
397
395
|
*/
|
|
398
396
|
function makeBasis(x, y, z) {
|
|
@@ -405,30 +403,6 @@ function makeBasis(x, y, z) {
|
|
|
405
403
|
];
|
|
406
404
|
/* eslint-enable prettier/prettier */
|
|
407
405
|
}
|
|
408
|
-
/**
|
|
409
|
-
* Creates a rotation matrix that is rotated around a given axis by the given
|
|
410
|
-
* angle.
|
|
411
|
-
*
|
|
412
|
-
* @param axis The axis of rotation.
|
|
413
|
-
* @param radians The angle of rotation.
|
|
414
|
-
* @returns A rotation matrix.
|
|
415
|
-
*/
|
|
416
|
-
function makeRotationAxis(axis, radians) {
|
|
417
|
-
var c = Math.cos(radians);
|
|
418
|
-
var s = Math.sin(radians);
|
|
419
|
-
var t = 1 - c;
|
|
420
|
-
var x = axis.x, y = axis.y, z = axis.z;
|
|
421
|
-
var tx = t * x;
|
|
422
|
-
var ty = t * y;
|
|
423
|
-
/* eslint-disable prettier/prettier */
|
|
424
|
-
return [
|
|
425
|
-
tx * x + c, tx * y + s * z, tx * z - s * y, 0,
|
|
426
|
-
tx * y - s * z, ty * y + c, ty * z + s * x, 0,
|
|
427
|
-
tx * z + s * y, ty * z - s * x, t * z * z + c, 0,
|
|
428
|
-
0, 0, 0, 1
|
|
429
|
-
];
|
|
430
|
-
/* eslint-enable prettier/prettier */
|
|
431
|
-
}
|
|
432
406
|
/**
|
|
433
407
|
* Creates a matrix used for [perspective
|
|
434
408
|
* projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
|
|
@@ -610,24 +584,24 @@ function invert(matrix) {
|
|
|
610
584
|
if (!det) {
|
|
611
585
|
return makeZero();
|
|
612
586
|
}
|
|
613
|
-
|
|
587
|
+
var oneOverDet = 1 / det;
|
|
614
588
|
return [
|
|
615
|
-
(a11 * b11 - a12 * b10 + a13 * b09) *
|
|
616
|
-
(a02 * b10 - a01 * b11 - a03 * b09) *
|
|
617
|
-
(a31 * b05 - a32 * b04 + a33 * b03) *
|
|
618
|
-
(a22 * b04 - a21 * b05 - a23 * b03) *
|
|
619
|
-
(a12 * b08 - a10 * b11 - a13 * b07) *
|
|
620
|
-
(a00 * b11 - a02 * b08 + a03 * b07) *
|
|
621
|
-
(a32 * b02 - a30 * b05 - a33 * b01) *
|
|
622
|
-
(a20 * b05 - a22 * b02 + a23 * b01) *
|
|
623
|
-
(a10 * b10 - a11 * b08 + a13 * b06) *
|
|
624
|
-
(a01 * b08 - a00 * b10 - a03 * b06) *
|
|
625
|
-
(a30 * b04 - a31 * b02 + a33 * b00) *
|
|
626
|
-
(a21 * b02 - a20 * b04 - a23 * b00) *
|
|
627
|
-
(a11 * b07 - a10 * b09 - a12 * b06) *
|
|
628
|
-
(a00 * b09 - a01 * b07 + a02 * b06) *
|
|
629
|
-
(a31 * b01 - a30 * b03 - a32 * b00) *
|
|
630
|
-
(a20 * b03 - a21 * b01 + a22 * b00) *
|
|
589
|
+
(a11 * b11 - a12 * b10 + a13 * b09) * oneOverDet,
|
|
590
|
+
(a02 * b10 - a01 * b11 - a03 * b09) * oneOverDet,
|
|
591
|
+
(a31 * b05 - a32 * b04 + a33 * b03) * oneOverDet,
|
|
592
|
+
(a22 * b04 - a21 * b05 - a23 * b03) * oneOverDet,
|
|
593
|
+
(a12 * b08 - a10 * b11 - a13 * b07) * oneOverDet,
|
|
594
|
+
(a00 * b11 - a02 * b08 + a03 * b07) * oneOverDet,
|
|
595
|
+
(a32 * b02 - a30 * b05 - a33 * b01) * oneOverDet,
|
|
596
|
+
(a20 * b05 - a22 * b02 + a23 * b01) * oneOverDet,
|
|
597
|
+
(a10 * b10 - a11 * b08 + a13 * b06) * oneOverDet,
|
|
598
|
+
(a01 * b08 - a00 * b10 - a03 * b06) * oneOverDet,
|
|
599
|
+
(a30 * b04 - a31 * b02 + a33 * b00) * oneOverDet,
|
|
600
|
+
(a21 * b02 - a20 * b04 - a23 * b00) * oneOverDet,
|
|
601
|
+
(a11 * b07 - a10 * b09 - a12 * b06) * oneOverDet,
|
|
602
|
+
(a00 * b09 - a01 * b07 + a02 * b06) * oneOverDet,
|
|
603
|
+
(a31 * b01 - a30 * b03 - a32 * b00) * oneOverDet,
|
|
604
|
+
(a20 * b03 - a21 * b01 + a22 * b00) * oneOverDet,
|
|
631
605
|
];
|
|
632
606
|
}
|
|
633
607
|
/**
|
|
@@ -662,49 +636,37 @@ function lookAt(m, position, target, up) {
|
|
|
662
636
|
var res = tslib.__spreadArray([], m, true);
|
|
663
637
|
/* eslint-disable prettier/prettier */
|
|
664
638
|
res[0] = x.x;
|
|
665
|
-
res[4] = y.x;
|
|
666
|
-
res[8] = z.x;
|
|
667
639
|
res[1] = x.y;
|
|
668
|
-
res[5] = y.y;
|
|
669
|
-
res[9] = z.y;
|
|
670
640
|
res[2] = x.z;
|
|
641
|
+
res[4] = y.x;
|
|
642
|
+
res[5] = y.y;
|
|
671
643
|
res[6] = y.z;
|
|
644
|
+
res[8] = z.x;
|
|
645
|
+
res[9] = z.y;
|
|
672
646
|
res[10] = z.z;
|
|
673
647
|
/* eslint-enable prettier/prettier */
|
|
674
648
|
return res;
|
|
675
649
|
}
|
|
676
650
|
/**
|
|
677
|
-
* Returns a post-multiplied matrix.
|
|
651
|
+
* Returns a post-multiplied matrix equal to ab.
|
|
678
652
|
*/
|
|
679
653
|
function multiply$2(a, b) {
|
|
680
|
-
var
|
|
681
|
-
|
|
682
|
-
var
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
mat[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
697
|
-
mat[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
698
|
-
mat[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
699
|
-
mat[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
700
|
-
mat[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
701
|
-
mat[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
702
|
-
mat[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
703
|
-
mat[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
704
|
-
mat[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
705
|
-
mat[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
706
|
-
mat[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
707
|
-
return mat;
|
|
654
|
+
var result = makeIdentity();
|
|
655
|
+
// Consider each row i in the final matrix
|
|
656
|
+
for (var i = 0; i < 4; i++) {
|
|
657
|
+
// Consider each column j in the final matrix
|
|
658
|
+
for (var j = 0; j < 4; j++) {
|
|
659
|
+
// Calculate the value at row i and column j
|
|
660
|
+
var value = 0;
|
|
661
|
+
for (var k = 0; k < 4; k++) {
|
|
662
|
+
// Calculate (ik + kj) and add it to the value
|
|
663
|
+
value += a[i * 4 + k] * b[k * 4 + j];
|
|
664
|
+
}
|
|
665
|
+
var positionInResultingMatrix = 4 * i + j;
|
|
666
|
+
result[positionInResultingMatrix] = value;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
return result;
|
|
708
670
|
}
|
|
709
671
|
/**
|
|
710
672
|
* Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
|
|
@@ -721,32 +683,37 @@ function transpose(matrix) {
|
|
|
721
683
|
/* eslint-enable prettier/prettier */
|
|
722
684
|
}
|
|
723
685
|
/**
|
|
724
|
-
* Multiplies the columns of a matrix by the given vector.
|
|
686
|
+
* Multiplies the columns of a row-major matrix by the given vector.
|
|
725
687
|
*/
|
|
726
688
|
function scale$4(matrix, scale) {
|
|
727
689
|
var x = scale.x, y = scale.y, z = scale.z;
|
|
728
690
|
var m = tslib.__spreadArray([], matrix, true);
|
|
729
691
|
/* eslint-disable prettier/prettier */
|
|
730
692
|
m[0] *= x;
|
|
731
|
-
m[4] *= y;
|
|
732
|
-
m[8] *= z;
|
|
733
693
|
m[1] *= x;
|
|
734
|
-
m[5] *= y;
|
|
735
|
-
m[9] *= z;
|
|
736
694
|
m[2] *= x;
|
|
737
|
-
m[6] *= y;
|
|
738
|
-
m[10] *= z;
|
|
739
695
|
m[3] *= x;
|
|
696
|
+
m[4] *= y;
|
|
697
|
+
m[5] *= y;
|
|
698
|
+
m[6] *= y;
|
|
740
699
|
m[7] *= y;
|
|
700
|
+
m[8] *= z;
|
|
701
|
+
m[9] *= z;
|
|
702
|
+
m[10] *= z;
|
|
741
703
|
m[11] *= z;
|
|
742
704
|
/* eslint-enable prettier/prettier */
|
|
743
705
|
return m;
|
|
744
706
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
707
|
+
/**
|
|
708
|
+
* Sets the position of the matrix given as the first parameter
|
|
709
|
+
* to the position of the matrix given as the second parameter.
|
|
710
|
+
* Both matrices should have row-major format.
|
|
711
|
+
*/
|
|
712
|
+
function position(originalMatrix, matrixWithDesiredPosition) {
|
|
713
|
+
var m = tslib.__spreadArray([], originalMatrix, true);
|
|
714
|
+
m[12] = matrixWithDesiredPosition[12];
|
|
715
|
+
m[13] = matrixWithDesiredPosition[13];
|
|
716
|
+
m[14] = matrixWithDesiredPosition[14];
|
|
750
717
|
return m;
|
|
751
718
|
}
|
|
752
719
|
/**
|
|
@@ -758,8 +725,18 @@ function isIdentity(matrix) {
|
|
|
758
725
|
}
|
|
759
726
|
/**
|
|
760
727
|
* Returns an object representation of a `Matrix4`.
|
|
728
|
+
* @param m A Matrix4 item written in column-major form.
|
|
729
|
+
*
|
|
730
|
+
* @deprecated Use {@link toObjectColumnMajor} or {@link toObjectRowMajor} instead.
|
|
761
731
|
*/
|
|
762
732
|
function toObject(m) {
|
|
733
|
+
return toObjectColumnMajor(m);
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Returns an object representation of a `Matrix4`.
|
|
737
|
+
* @param m A Matrix4 item written in column-major form.
|
|
738
|
+
*/
|
|
739
|
+
function toObjectColumnMajor(m) {
|
|
763
740
|
/* eslint-disable prettier/prettier */
|
|
764
741
|
return {
|
|
765
742
|
m11: m[0], m12: m[4], m13: m[8], m14: m[12],
|
|
@@ -769,6 +746,20 @@ function toObject(m) {
|
|
|
769
746
|
};
|
|
770
747
|
/* eslint-enable prettier/prettier */
|
|
771
748
|
}
|
|
749
|
+
/**
|
|
750
|
+
* Returns an object representation of a `Matrix4`.
|
|
751
|
+
* @param m A Matrix4 item written in row-major form.
|
|
752
|
+
*/
|
|
753
|
+
function toObjectRowMajor(m) {
|
|
754
|
+
/* eslint-disable prettier/prettier */
|
|
755
|
+
return {
|
|
756
|
+
m11: m[0], m12: m[1], m13: m[2], m14: m[3],
|
|
757
|
+
m21: m[4], m22: m[5], m23: m[6], m24: m[7],
|
|
758
|
+
m31: m[8], m32: m[9], m33: m[10], m34: m[11],
|
|
759
|
+
m41: m[12], m42: m[13], m43: m[14], m44: m[15],
|
|
760
|
+
};
|
|
761
|
+
/* eslint-enable prettier/prettier */
|
|
762
|
+
}
|
|
772
763
|
/**
|
|
773
764
|
* A type guard to check if `obj` is of type `Matrix4`.
|
|
774
765
|
*/
|
|
@@ -778,30 +769,31 @@ function isType$2(obj) {
|
|
|
778
769
|
|
|
779
770
|
var matrix4 = /*#__PURE__*/Object.freeze({
|
|
780
771
|
__proto__: null,
|
|
781
|
-
fromValues: fromValues,
|
|
782
772
|
fromObject: fromObject,
|
|
773
|
+
fromValues: fromValues,
|
|
774
|
+
invert: invert,
|
|
775
|
+
isIdentity: isIdentity,
|
|
776
|
+
isType: isType$2,
|
|
777
|
+
lookAt: lookAt,
|
|
778
|
+
makeBasis: makeBasis,
|
|
779
|
+
makeFrustum: makeFrustum,
|
|
783
780
|
makeIdentity: makeIdentity,
|
|
784
|
-
|
|
785
|
-
|
|
781
|
+
makeLookAt: makeLookAt,
|
|
782
|
+
makeLookAtView: makeLookAtView,
|
|
783
|
+
makeOrthographic: makeOrthographic,
|
|
784
|
+
makePerspective: makePerspective,
|
|
786
785
|
makeRotation: makeRotation,
|
|
787
786
|
makeScale: makeScale,
|
|
788
787
|
makeTRS: makeTRS,
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
makeFrustum: makeFrustum,
|
|
792
|
-
makePerspective: makePerspective,
|
|
793
|
-
makeOrthographic: makeOrthographic,
|
|
794
|
-
makeLookAtView: makeLookAtView,
|
|
795
|
-
makeLookAt: makeLookAt,
|
|
796
|
-
invert: invert,
|
|
797
|
-
lookAt: lookAt,
|
|
788
|
+
makeTranslation: makeTranslation,
|
|
789
|
+
makeZero: makeZero,
|
|
798
790
|
multiply: multiply$2,
|
|
799
|
-
transpose: transpose,
|
|
800
|
-
scale: scale$4,
|
|
801
791
|
position: position,
|
|
802
|
-
|
|
792
|
+
scale: scale$4,
|
|
803
793
|
toObject: toObject,
|
|
804
|
-
|
|
794
|
+
toObjectColumnMajor: toObjectColumnMajor,
|
|
795
|
+
toObjectRowMajor: toObjectRowMajor,
|
|
796
|
+
transpose: transpose
|
|
805
797
|
});
|
|
806
798
|
|
|
807
799
|
/**
|
|
@@ -851,9 +843,12 @@ function fromDegrees(value) {
|
|
|
851
843
|
* @param matrix A pure rotation matrix, unscaled.
|
|
852
844
|
* @param order The order that the rotations are applied.
|
|
853
845
|
*/
|
|
854
|
-
function fromRotationMatrix(matrix, order) {
|
|
846
|
+
function fromRotationMatrix(matrix, order, matrixIsColumnMajor) {
|
|
855
847
|
if (order === void 0) { order = 'xyz'; }
|
|
856
|
-
|
|
848
|
+
if (matrixIsColumnMajor === void 0) { matrixIsColumnMajor = true; }
|
|
849
|
+
var m = matrixIsColumnMajor
|
|
850
|
+
? toObjectColumnMajor(matrix)
|
|
851
|
+
: toObjectRowMajor(matrix);
|
|
857
852
|
var x = 0, y = 0, z = 0;
|
|
858
853
|
if (order === 'xyz') {
|
|
859
854
|
y = Math.asin(clamp(m.m13, -1, 1));
|
|
@@ -959,8 +954,8 @@ var euler = /*#__PURE__*/Object.freeze({
|
|
|
959
954
|
__proto__: null,
|
|
960
955
|
create: create$c,
|
|
961
956
|
fromDegrees: fromDegrees,
|
|
962
|
-
fromRotationMatrix: fromRotationMatrix,
|
|
963
957
|
fromJson: fromJson$4,
|
|
958
|
+
fromRotationMatrix: fromRotationMatrix,
|
|
964
959
|
isType: isType$1
|
|
965
960
|
});
|
|
966
961
|
|
|
@@ -1032,55 +1027,47 @@ function fromAxisAngle(axis, radians) {
|
|
|
1032
1027
|
* (unscaled).
|
|
1033
1028
|
*/
|
|
1034
1029
|
function fromMatrixRotation(matrix) {
|
|
1035
|
-
|
|
1030
|
+
// Determine the scalars for each vector
|
|
1036
1031
|
var scale = fromMatrixScale(matrix);
|
|
1037
|
-
var
|
|
1038
|
-
|
|
1039
|
-
var
|
|
1040
|
-
var
|
|
1041
|
-
var
|
|
1042
|
-
var sm13 = m.m31 * is3;
|
|
1043
|
-
var sm21 = m.m12 * is1;
|
|
1044
|
-
var sm22 = m.m22 * is2;
|
|
1045
|
-
var sm23 = m.m32 * is3;
|
|
1046
|
-
var sm31 = m.m13 * is1;
|
|
1047
|
-
var sm32 = m.m23 * is2;
|
|
1048
|
-
var sm33 = m.m33 * is3;
|
|
1049
|
-
var trace = sm11 + sm22 + sm33;
|
|
1032
|
+
var oneOverScaleVector = create$a(1 / scale.x, 1 / scale.y, 1 / scale.z);
|
|
1033
|
+
// Scale the matrix
|
|
1034
|
+
var scaledMatrix = scale$4(matrix, oneOverScaleVector);
|
|
1035
|
+
var sM = toObjectRowMajor(scaledMatrix);
|
|
1036
|
+
var trace = sM.m11 + sM.m22 + sM.m33;
|
|
1050
1037
|
if (trace > 0) {
|
|
1051
|
-
var s = Math.sqrt(trace + 1
|
|
1038
|
+
var s = Math.sqrt(trace + 1) * 2;
|
|
1052
1039
|
return {
|
|
1053
|
-
x: (
|
|
1054
|
-
y: (
|
|
1055
|
-
z: (
|
|
1040
|
+
x: (sM.m23 - sM.m32) / s,
|
|
1041
|
+
y: (sM.m31 - sM.m13) / s,
|
|
1042
|
+
z: (sM.m12 - sM.m21) / s,
|
|
1056
1043
|
w: 0.25 * s,
|
|
1057
1044
|
};
|
|
1058
1045
|
}
|
|
1059
|
-
else if (
|
|
1060
|
-
var s = Math.sqrt(1
|
|
1046
|
+
else if (sM.m11 > sM.m22 && sM.m11 > sM.m33) {
|
|
1047
|
+
var s = Math.sqrt(1 + sM.m11 - sM.m22 - sM.m33) * 2;
|
|
1061
1048
|
return {
|
|
1062
1049
|
x: 0.25 * s,
|
|
1063
|
-
y: (
|
|
1064
|
-
z: (
|
|
1065
|
-
w: (
|
|
1050
|
+
y: (sM.m12 + sM.m21) / s,
|
|
1051
|
+
z: (sM.m31 + sM.m13) / s,
|
|
1052
|
+
w: (sM.m23 - sM.m32) / s,
|
|
1066
1053
|
};
|
|
1067
1054
|
}
|
|
1068
|
-
else if (
|
|
1069
|
-
var s = Math.sqrt(1
|
|
1055
|
+
else if (sM.m22 > sM.m33) {
|
|
1056
|
+
var s = Math.sqrt(1 + sM.m22 - sM.m11 - sM.m33) * 2;
|
|
1070
1057
|
return {
|
|
1071
|
-
x: (
|
|
1058
|
+
x: (sM.m12 + sM.m21) / s,
|
|
1072
1059
|
y: 0.25 * s,
|
|
1073
|
-
z: (
|
|
1074
|
-
w: (
|
|
1060
|
+
z: (sM.m23 + sM.m32) / s,
|
|
1061
|
+
w: (sM.m31 - sM.m13) / s,
|
|
1075
1062
|
};
|
|
1076
1063
|
}
|
|
1077
1064
|
else {
|
|
1078
|
-
var s = Math.sqrt(1
|
|
1065
|
+
var s = Math.sqrt(1 + sM.m33 - sM.m11 - sM.m22) * 2;
|
|
1079
1066
|
return {
|
|
1080
|
-
x: (
|
|
1081
|
-
y: (
|
|
1067
|
+
x: (sM.m31 + sM.m13) / s,
|
|
1068
|
+
y: (sM.m23 + sM.m32) / s,
|
|
1082
1069
|
z: 0.25 * s,
|
|
1083
|
-
w: (
|
|
1070
|
+
w: (sM.m12 - sM.m21) / s,
|
|
1084
1071
|
};
|
|
1085
1072
|
}
|
|
1086
1073
|
}
|
|
@@ -1161,15 +1148,15 @@ function isType(obj) {
|
|
|
1161
1148
|
var quaternion = /*#__PURE__*/Object.freeze({
|
|
1162
1149
|
__proto__: null,
|
|
1163
1150
|
create: create$b,
|
|
1164
|
-
fromJson: fromJson$3,
|
|
1165
|
-
normalize: normalize$1,
|
|
1166
|
-
magnitude: magnitude$1,
|
|
1167
|
-
scale: scale$3,
|
|
1168
1151
|
fromAxisAngle: fromAxisAngle,
|
|
1169
|
-
fromMatrixRotation: fromMatrixRotation,
|
|
1170
1152
|
fromEuler: fromEuler,
|
|
1153
|
+
fromJson: fromJson$3,
|
|
1154
|
+
fromMatrixRotation: fromMatrixRotation,
|
|
1155
|
+
isType: isType,
|
|
1156
|
+
magnitude: magnitude$1,
|
|
1171
1157
|
multiply: multiply$1,
|
|
1172
|
-
|
|
1158
|
+
normalize: normalize$1,
|
|
1159
|
+
scale: scale$3
|
|
1173
1160
|
});
|
|
1174
1161
|
|
|
1175
1162
|
function create$a() {
|
|
@@ -1212,19 +1199,19 @@ function isValid$1(_a) {
|
|
|
1212
1199
|
* Returns a vector representing the scale elements of `matrix`.
|
|
1213
1200
|
*/
|
|
1214
1201
|
function fromMatrixScale(matrix) {
|
|
1215
|
-
var m =
|
|
1202
|
+
var m = toObjectRowMajor(matrix);
|
|
1216
1203
|
return {
|
|
1217
|
-
x: Math.hypot(m.m11, m.
|
|
1218
|
-
y: Math.hypot(m.
|
|
1219
|
-
z: Math.hypot(m.
|
|
1204
|
+
x: Math.hypot(m.m11, m.m12, m.m13),
|
|
1205
|
+
y: Math.hypot(m.m21, m.m22, m.m23),
|
|
1206
|
+
z: Math.hypot(m.m31, m.m32, m.m33),
|
|
1220
1207
|
};
|
|
1221
1208
|
}
|
|
1222
1209
|
/**
|
|
1223
1210
|
* Returns a vector representing the position elements of `matrix`.
|
|
1224
1211
|
*/
|
|
1225
1212
|
function fromMatrixPosition(matrix) {
|
|
1226
|
-
var m =
|
|
1227
|
-
return { x: m.
|
|
1213
|
+
var m = toObjectRowMajor(matrix);
|
|
1214
|
+
return { x: m.m41, y: m.m42, z: m.m43 };
|
|
1228
1215
|
}
|
|
1229
1216
|
/**
|
|
1230
1217
|
* Parses a JSON string representation of a Vector3 and returns an object.
|
|
@@ -1422,7 +1409,7 @@ function eulerTo(a, b) {
|
|
|
1422
1409
|
return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
|
|
1423
1410
|
}
|
|
1424
1411
|
var normalizedQ = normalize$1(create$b(tslib.__assign({ w: 1 + dotAB }, cross(normalizedA, normalizedB))));
|
|
1425
|
-
return fromRotationMatrix(makeRotation(normalizedQ));
|
|
1412
|
+
return fromRotationMatrix(makeRotation(normalizedQ), 'xyz', false);
|
|
1426
1413
|
}
|
|
1427
1414
|
/**
|
|
1428
1415
|
* Performs a projection of a `vector` onto `onNormal`.
|
|
@@ -1474,9 +1461,21 @@ function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
|
|
|
1474
1461
|
}
|
|
1475
1462
|
}
|
|
1476
1463
|
/**
|
|
1477
|
-
* Returns a vector that is multiplied with a matrix.
|
|
1464
|
+
* Returns a vector that is multiplied with a matrix in column-major form.
|
|
1465
|
+
* @param vector A Vector3 item.
|
|
1466
|
+
* @param m A Matrix4 item written in column-major form.
|
|
1467
|
+
*
|
|
1468
|
+
* @deprecated Use {@link multiplyByTransformMatrixColumnMajor} or {@link multiplyByTransformMatrixRowMajor} instead.
|
|
1478
1469
|
*/
|
|
1479
1470
|
function transformMatrix$1(vector, m) {
|
|
1471
|
+
return multiplyByTransformMatrixColumnMajor(vector, m);
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Returns a vector that is multiplied with a matrix in column-major form.
|
|
1475
|
+
* @param vector A Vector3 item.
|
|
1476
|
+
* @param m A Matrix4 item written in column-major form.
|
|
1477
|
+
*/
|
|
1478
|
+
function multiplyByTransformMatrixColumnMajor(vector, m) {
|
|
1480
1479
|
var x = vector.x, y = vector.y, z = vector.z;
|
|
1481
1480
|
var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
|
|
1482
1481
|
return {
|
|
@@ -1485,6 +1484,20 @@ function transformMatrix$1(vector, m) {
|
|
|
1485
1484
|
z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
|
|
1486
1485
|
};
|
|
1487
1486
|
}
|
|
1487
|
+
/**
|
|
1488
|
+
* Returns a vector that is multiplied with a matrix in row-major form.
|
|
1489
|
+
* @param vector A Vector3 item.
|
|
1490
|
+
* @param m A Matrix4 item written in row-major form.
|
|
1491
|
+
*/
|
|
1492
|
+
function multiplyByTransformMatrixRowMajor(vector, m) {
|
|
1493
|
+
var x = vector.x, y = vector.y, z = vector.z;
|
|
1494
|
+
var w = 1 / (m[12] * x + m[13] * y + m[14] * z + m[15]);
|
|
1495
|
+
return {
|
|
1496
|
+
x: (m[0] * x + m[1] * y + m[2] * z + m[3]) * w,
|
|
1497
|
+
y: (m[4] * x + m[5] * y + m[6] * z + m[7]) * w,
|
|
1498
|
+
z: (m[8] * x + m[9] * y + m[10] * z + m[11]) * w,
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1488
1501
|
/**
|
|
1489
1502
|
* Euclidean distance between two vectors
|
|
1490
1503
|
*/
|
|
@@ -1548,47 +1561,49 @@ function lerp(a, b, t) {
|
|
|
1548
1561
|
* @returns A point in world space coordinates.
|
|
1549
1562
|
*/
|
|
1550
1563
|
function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
|
|
1551
|
-
return
|
|
1564
|
+
return multiplyByTransformMatrixColumnMajor(multiplyByTransformMatrixColumnMajor(ndc, projectionMatrixInverse), worldMatrix);
|
|
1552
1565
|
}
|
|
1553
1566
|
|
|
1554
1567
|
var vector3 = /*#__PURE__*/Object.freeze({
|
|
1555
1568
|
__proto__: null,
|
|
1569
|
+
add: add,
|
|
1570
|
+
angleTo: angleTo,
|
|
1571
|
+
back: back,
|
|
1556
1572
|
create: create$a,
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
right: right,
|
|
1564
|
-
up: up,
|
|
1573
|
+
cross: cross,
|
|
1574
|
+
distance: distance$1,
|
|
1575
|
+
distanceSquared: distanceSquared$1,
|
|
1576
|
+
dot: dot$1,
|
|
1577
|
+
down: down,
|
|
1578
|
+
eulerTo: eulerTo,
|
|
1565
1579
|
forward: forward,
|
|
1580
|
+
fromArray: fromArray,
|
|
1581
|
+
fromJson: fromJson$2,
|
|
1582
|
+
fromMatrixPosition: fromMatrixPosition,
|
|
1583
|
+
fromMatrixScale: fromMatrixScale,
|
|
1584
|
+
isEqual: isEqual$2,
|
|
1585
|
+
isValid: isValid$1,
|
|
1566
1586
|
left: left,
|
|
1567
|
-
|
|
1568
|
-
back: back,
|
|
1569
|
-
origin: origin,
|
|
1570
|
-
normalize: normalize,
|
|
1587
|
+
lerp: lerp,
|
|
1571
1588
|
magnitude: magnitude,
|
|
1572
1589
|
magnitudeSquared: magnitudeSquared,
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
subtract: subtract,
|
|
1590
|
+
max: max,
|
|
1591
|
+
min: min,
|
|
1576
1592
|
multiply: multiply,
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1593
|
+
multiplyByTransformMatrixColumnMajor: multiplyByTransformMatrixColumnMajor,
|
|
1594
|
+
multiplyByTransformMatrixRowMajor: multiplyByTransformMatrixRowMajor,
|
|
1595
|
+
negate: negate,
|
|
1596
|
+
normalize: normalize,
|
|
1597
|
+
origin: origin,
|
|
1581
1598
|
project: project,
|
|
1599
|
+
right: right,
|
|
1582
1600
|
rotateAboutAxis: rotateAboutAxis,
|
|
1601
|
+
scale: scale$2,
|
|
1602
|
+
subtract: subtract,
|
|
1603
|
+
toArray: toArray,
|
|
1583
1604
|
transformMatrix: transformMatrix$1,
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
isEqual: isEqual$2,
|
|
1587
|
-
max: max,
|
|
1588
|
-
min: min,
|
|
1589
|
-
negate: negate,
|
|
1590
|
-
lerp: lerp,
|
|
1591
|
-
transformNdcToWorldSpace: transformNdcToWorldSpace
|
|
1605
|
+
transformNdcToWorldSpace: transformNdcToWorldSpace,
|
|
1606
|
+
up: up
|
|
1592
1607
|
});
|
|
1593
1608
|
|
|
1594
1609
|
/**
|
|
@@ -1653,14 +1668,14 @@ function isValid(boundingBox) {
|
|
|
1653
1668
|
|
|
1654
1669
|
var boundingBox = /*#__PURE__*/Object.freeze({
|
|
1655
1670
|
__proto__: null,
|
|
1656
|
-
create: create$9,
|
|
1657
|
-
fromVectors: fromVectors,
|
|
1658
1671
|
center: center$3,
|
|
1672
|
+
create: create$9,
|
|
1659
1673
|
diagonal: diagonal,
|
|
1660
1674
|
epsilon: epsilon,
|
|
1661
|
-
|
|
1675
|
+
fromVectors: fromVectors,
|
|
1676
|
+
isValid: isValid,
|
|
1662
1677
|
lengths: lengths,
|
|
1663
|
-
|
|
1678
|
+
union: union
|
|
1664
1679
|
});
|
|
1665
1680
|
|
|
1666
1681
|
/**
|
|
@@ -1874,26 +1889,26 @@ function fromJson$1(json) {
|
|
|
1874
1889
|
|
|
1875
1890
|
var rectangle = /*#__PURE__*/Object.freeze({
|
|
1876
1891
|
__proto__: null,
|
|
1892
|
+
area: area$1,
|
|
1893
|
+
bottomRight: bottomRight,
|
|
1894
|
+
center: center$2,
|
|
1895
|
+
containFit: containFit$1,
|
|
1896
|
+
containsPoints: containsPoints,
|
|
1877
1897
|
create: create$7,
|
|
1898
|
+
cropFit: cropFit$1,
|
|
1878
1899
|
fromDimensions: fromDimensions,
|
|
1900
|
+
fromJson: fromJson$1,
|
|
1879
1901
|
fromPointAndDimensions: fromPointAndDimensions,
|
|
1880
1902
|
fromPoints: fromPoints,
|
|
1881
|
-
containFit: containFit$1,
|
|
1882
|
-
cropFit: cropFit$1,
|
|
1883
|
-
scaleFit: scaleFit$1,
|
|
1884
|
-
scale: scale$1,
|
|
1885
1903
|
isEqual: isEqual$1,
|
|
1886
|
-
offset: offset,
|
|
1887
|
-
area: area$1,
|
|
1888
|
-
center: center$2,
|
|
1889
|
-
topLeft: topLeft,
|
|
1890
|
-
bottomRight: bottomRight,
|
|
1891
|
-
isPortrait: isPortrait,
|
|
1892
1904
|
isLandscape: isLandscape,
|
|
1905
|
+
isPortrait: isPortrait,
|
|
1893
1906
|
isSquare: isSquare,
|
|
1907
|
+
offset: offset,
|
|
1894
1908
|
pad: pad,
|
|
1895
|
-
|
|
1896
|
-
|
|
1909
|
+
scale: scale$1,
|
|
1910
|
+
scaleFit: scaleFit$1,
|
|
1911
|
+
topLeft: topLeft
|
|
1897
1912
|
});
|
|
1898
1913
|
|
|
1899
1914
|
/**
|
|
@@ -2037,22 +2052,22 @@ function toRectangle(dimensions, position) {
|
|
|
2037
2052
|
|
|
2038
2053
|
var dimensions = /*#__PURE__*/Object.freeze({
|
|
2039
2054
|
__proto__: null,
|
|
2055
|
+
area: area,
|
|
2056
|
+
aspectRatio: aspectRatio,
|
|
2057
|
+
center: center$1,
|
|
2058
|
+
containFit: containFit,
|
|
2040
2059
|
create: create$6,
|
|
2041
|
-
|
|
2060
|
+
cropFit: cropFit,
|
|
2061
|
+
fitToRatio: fitToRatio,
|
|
2062
|
+
floor: floor,
|
|
2042
2063
|
isEqual: isEqual,
|
|
2043
|
-
scale: scale,
|
|
2044
2064
|
proportionalScale: proportionalScale,
|
|
2045
|
-
trim: trim,
|
|
2046
|
-
containFit: containFit,
|
|
2047
|
-
cropFit: cropFit,
|
|
2048
|
-
scaleFit: scaleFit,
|
|
2049
2065
|
round: round,
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
toRectangle: toRectangle
|
|
2066
|
+
scale: scale,
|
|
2067
|
+
scaleFit: scaleFit,
|
|
2068
|
+
square: square,
|
|
2069
|
+
toRectangle: toRectangle,
|
|
2070
|
+
trim: trim
|
|
2056
2071
|
});
|
|
2057
2072
|
|
|
2058
2073
|
/**
|
|
@@ -2084,8 +2099,8 @@ function center(line) {
|
|
|
2084
2099
|
* @returns A transformed line.
|
|
2085
2100
|
*/
|
|
2086
2101
|
function transformMatrix(line, matrix) {
|
|
2087
|
-
var start =
|
|
2088
|
-
var end =
|
|
2102
|
+
var start = multiplyByTransformMatrixColumnMajor(line.start, matrix);
|
|
2103
|
+
var end = multiplyByTransformMatrixColumnMajor(line.end, matrix);
|
|
2089
2104
|
return { start: start, end: end };
|
|
2090
2105
|
}
|
|
2091
2106
|
/**
|
|
@@ -2110,12 +2125,12 @@ function direction(line) {
|
|
|
2110
2125
|
|
|
2111
2126
|
var line3 = /*#__PURE__*/Object.freeze({
|
|
2112
2127
|
__proto__: null,
|
|
2113
|
-
create: create$5,
|
|
2114
2128
|
center: center,
|
|
2115
|
-
|
|
2129
|
+
create: create$5,
|
|
2130
|
+
direction: direction,
|
|
2116
2131
|
distance: distance,
|
|
2117
2132
|
distanceSquared: distanceSquared,
|
|
2118
|
-
|
|
2133
|
+
transformMatrix: transformMatrix
|
|
2119
2134
|
});
|
|
2120
2135
|
|
|
2121
2136
|
/**
|
|
@@ -2184,11 +2199,11 @@ var matrix = /*#__PURE__*/Object.freeze({
|
|
|
2184
2199
|
__proto__: null,
|
|
2185
2200
|
create: create$4,
|
|
2186
2201
|
identity: identity,
|
|
2187
|
-
translation: translation,
|
|
2188
|
-
rotation: rotation,
|
|
2189
2202
|
rotate: rotate,
|
|
2203
|
+
rotation: rotation,
|
|
2204
|
+
transformPoint: transformPoint,
|
|
2190
2205
|
translate: translate,
|
|
2191
|
-
|
|
2206
|
+
translation: translation
|
|
2192
2207
|
});
|
|
2193
2208
|
|
|
2194
2209
|
function create$3() {
|
|
@@ -2313,8 +2328,8 @@ function projectPoint(plane, point) {
|
|
|
2313
2328
|
var plane = /*#__PURE__*/Object.freeze({
|
|
2314
2329
|
__proto__: null,
|
|
2315
2330
|
create: create$2,
|
|
2316
|
-
fromNormalAndCoplanarPoint: fromNormalAndCoplanarPoint,
|
|
2317
2331
|
distanceToPoint: distanceToPoint,
|
|
2332
|
+
fromNormalAndCoplanarPoint: fromNormalAndCoplanarPoint,
|
|
2318
2333
|
intersectLine: intersectLine,
|
|
2319
2334
|
projectPoint: projectPoint
|
|
2320
2335
|
});
|
|
@@ -2381,8 +2396,8 @@ function intersectPlane(ray, plane) {
|
|
|
2381
2396
|
|
|
2382
2397
|
var ray = /*#__PURE__*/Object.freeze({
|
|
2383
2398
|
__proto__: null,
|
|
2384
|
-
create: create$1,
|
|
2385
2399
|
at: at,
|
|
2400
|
+
create: create$1,
|
|
2386
2401
|
distanceToPlane: distanceToPlane,
|
|
2387
2402
|
intersectPlane: intersectPlane
|
|
2388
2403
|
});
|