@vertexvis/geometry 1.0.2-testing.3 → 1.0.2-testing.4
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 +166 -149
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.js +166 -149
- package/dist/bundle.js.map +1 -1
- package/dist/cdn/bundle.js +166 -149
- 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 +3 -3
package/dist/cdn/bundle.js
CHANGED
|
@@ -257,10 +257,10 @@ function fromValues(
|
|
|
257
257
|
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44) {
|
|
258
258
|
/* eslint-disable prettier/prettier */
|
|
259
259
|
return [
|
|
260
|
-
m11,
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
m11, m12, m13, m14,
|
|
261
|
+
m21, m22, m23, m24,
|
|
262
|
+
m31, m32, m33, m34,
|
|
263
|
+
m41, m42, m43, m44,
|
|
264
264
|
];
|
|
265
265
|
/* eslint-enable prettier/prettier */
|
|
266
266
|
}
|
|
@@ -330,9 +330,9 @@ function makeRotation(rotation) {
|
|
|
330
330
|
var wx = w * x2, wy = w * y2, wz = w * z2;
|
|
331
331
|
/* eslint-disable prettier/prettier */
|
|
332
332
|
return [
|
|
333
|
-
1 - (yy + zz), xy
|
|
334
|
-
xy
|
|
335
|
-
xz
|
|
333
|
+
1 - (yy + zz), xy - wz, xz + wy, 0,
|
|
334
|
+
xy + wz, 1 - (xx + zz), yz - wx, 0,
|
|
335
|
+
xz - wy, yz + wx, 1 - (xx + yy), 0,
|
|
336
336
|
0, 0, 0, 1
|
|
337
337
|
];
|
|
338
338
|
/* eslint-enable prettier/prettier */
|
|
@@ -362,33 +362,33 @@ function makeScale(scale) {
|
|
|
362
362
|
/* eslint-enable prettier/prettier */
|
|
363
363
|
}
|
|
364
364
|
/**
|
|
365
|
-
* Creates a matrix that has translation, rotation and scale applied to it.
|
|
365
|
+
* Creates a matrix that has translation, rotation, and scale applied to it.
|
|
366
366
|
*
|
|
367
367
|
* @param translation The translation applied to the matrix.
|
|
368
368
|
* @param rotation The rotation applied to the matrix.
|
|
369
369
|
* @param scale The scale applied to the matrix.
|
|
370
|
-
* @returns A transformed matrix.
|
|
370
|
+
* @returns A transformed matrix in column-major form.
|
|
371
371
|
*/
|
|
372
372
|
function makeTRS(translation, rotation, scale) {
|
|
373
373
|
var t = makeTranslation(translation);
|
|
374
|
-
var r = makeRotation(rotation);
|
|
374
|
+
var r = transpose(makeRotation(rotation));
|
|
375
375
|
var s = makeScale(scale);
|
|
376
|
-
return multiply$2(multiply$2(
|
|
376
|
+
return multiply$2(s, multiply$2(r, t));
|
|
377
377
|
}
|
|
378
378
|
/**
|
|
379
379
|
* Returns a matrix that has the basis components (upper left 3x3 matrix) set to
|
|
380
380
|
* the following x, y, and z axis.
|
|
381
381
|
*
|
|
382
382
|
* ```
|
|
383
|
-
* x.x y.
|
|
384
|
-
* x.y y.
|
|
385
|
-
* x.
|
|
383
|
+
* x.x x.y x.z 0
|
|
384
|
+
* y.x y.y y.z 0
|
|
385
|
+
* z.x z.y z.z 0
|
|
386
386
|
* 0 0 0 0
|
|
387
387
|
* ```
|
|
388
388
|
*
|
|
389
|
-
* @param x The x
|
|
390
|
-
* @param y The y
|
|
391
|
-
* @param z The z
|
|
389
|
+
* @param x The x-axis to set.
|
|
390
|
+
* @param y The y-axis to set.
|
|
391
|
+
* @param z The z-axis to set.
|
|
392
392
|
* @returns A matrix with its basis components populated.
|
|
393
393
|
*/
|
|
394
394
|
function makeBasis(x, y, z) {
|
|
@@ -401,30 +401,6 @@ function makeBasis(x, y, z) {
|
|
|
401
401
|
];
|
|
402
402
|
/* eslint-enable prettier/prettier */
|
|
403
403
|
}
|
|
404
|
-
/**
|
|
405
|
-
* Creates a rotation matrix that is rotated around a given axis by the given
|
|
406
|
-
* angle.
|
|
407
|
-
*
|
|
408
|
-
* @param axis The axis of rotation.
|
|
409
|
-
* @param radians The angle of rotation.
|
|
410
|
-
* @returns A rotation matrix.
|
|
411
|
-
*/
|
|
412
|
-
function makeRotationAxis(axis, radians) {
|
|
413
|
-
var c = Math.cos(radians);
|
|
414
|
-
var s = Math.sin(radians);
|
|
415
|
-
var t = 1 - c;
|
|
416
|
-
var x = axis.x, y = axis.y, z = axis.z;
|
|
417
|
-
var tx = t * x;
|
|
418
|
-
var ty = t * y;
|
|
419
|
-
/* eslint-disable prettier/prettier */
|
|
420
|
-
return [
|
|
421
|
-
tx * x + c, tx * y + s * z, tx * z - s * y, 0,
|
|
422
|
-
tx * y - s * z, ty * y + c, ty * z + s * x, 0,
|
|
423
|
-
tx * z + s * y, ty * z - s * x, t * z * z + c, 0,
|
|
424
|
-
0, 0, 0, 1
|
|
425
|
-
];
|
|
426
|
-
/* eslint-enable prettier/prettier */
|
|
427
|
-
}
|
|
428
404
|
/**
|
|
429
405
|
* Creates a matrix used for [perspective
|
|
430
406
|
* projections](https://en.wikipedia.org/wiki/3D_projection#Perspective_projection).
|
|
@@ -606,24 +582,24 @@ function invert(matrix) {
|
|
|
606
582
|
if (!det) {
|
|
607
583
|
return makeZero();
|
|
608
584
|
}
|
|
609
|
-
|
|
585
|
+
var oneOverDet = 1 / det;
|
|
610
586
|
return [
|
|
611
|
-
(a11 * b11 - a12 * b10 + a13 * b09) *
|
|
612
|
-
(a02 * b10 - a01 * b11 - a03 * b09) *
|
|
613
|
-
(a31 * b05 - a32 * b04 + a33 * b03) *
|
|
614
|
-
(a22 * b04 - a21 * b05 - a23 * b03) *
|
|
615
|
-
(a12 * b08 - a10 * b11 - a13 * b07) *
|
|
616
|
-
(a00 * b11 - a02 * b08 + a03 * b07) *
|
|
617
|
-
(a32 * b02 - a30 * b05 - a33 * b01) *
|
|
618
|
-
(a20 * b05 - a22 * b02 + a23 * b01) *
|
|
619
|
-
(a10 * b10 - a11 * b08 + a13 * b06) *
|
|
620
|
-
(a01 * b08 - a00 * b10 - a03 * b06) *
|
|
621
|
-
(a30 * b04 - a31 * b02 + a33 * b00) *
|
|
622
|
-
(a21 * b02 - a20 * b04 - a23 * b00) *
|
|
623
|
-
(a11 * b07 - a10 * b09 - a12 * b06) *
|
|
624
|
-
(a00 * b09 - a01 * b07 + a02 * b06) *
|
|
625
|
-
(a31 * b01 - a30 * b03 - a32 * b00) *
|
|
626
|
-
(a20 * b03 - a21 * b01 + a22 * b00) *
|
|
587
|
+
(a11 * b11 - a12 * b10 + a13 * b09) * oneOverDet,
|
|
588
|
+
(a02 * b10 - a01 * b11 - a03 * b09) * oneOverDet,
|
|
589
|
+
(a31 * b05 - a32 * b04 + a33 * b03) * oneOverDet,
|
|
590
|
+
(a22 * b04 - a21 * b05 - a23 * b03) * oneOverDet,
|
|
591
|
+
(a12 * b08 - a10 * b11 - a13 * b07) * oneOverDet,
|
|
592
|
+
(a00 * b11 - a02 * b08 + a03 * b07) * oneOverDet,
|
|
593
|
+
(a32 * b02 - a30 * b05 - a33 * b01) * oneOverDet,
|
|
594
|
+
(a20 * b05 - a22 * b02 + a23 * b01) * oneOverDet,
|
|
595
|
+
(a10 * b10 - a11 * b08 + a13 * b06) * oneOverDet,
|
|
596
|
+
(a01 * b08 - a00 * b10 - a03 * b06) * oneOverDet,
|
|
597
|
+
(a30 * b04 - a31 * b02 + a33 * b00) * oneOverDet,
|
|
598
|
+
(a21 * b02 - a20 * b04 - a23 * b00) * oneOverDet,
|
|
599
|
+
(a11 * b07 - a10 * b09 - a12 * b06) * oneOverDet,
|
|
600
|
+
(a00 * b09 - a01 * b07 + a02 * b06) * oneOverDet,
|
|
601
|
+
(a31 * b01 - a30 * b03 - a32 * b00) * oneOverDet,
|
|
602
|
+
(a20 * b03 - a21 * b01 + a22 * b00) * oneOverDet,
|
|
627
603
|
];
|
|
628
604
|
}
|
|
629
605
|
/**
|
|
@@ -658,49 +634,37 @@ function lookAt(m, position, target, up) {
|
|
|
658
634
|
var res = __spreadArray([], m, true);
|
|
659
635
|
/* eslint-disable prettier/prettier */
|
|
660
636
|
res[0] = x.x;
|
|
661
|
-
res[4] = y.x;
|
|
662
|
-
res[8] = z.x;
|
|
663
637
|
res[1] = x.y;
|
|
664
|
-
res[5] = y.y;
|
|
665
|
-
res[9] = z.y;
|
|
666
638
|
res[2] = x.z;
|
|
639
|
+
res[4] = y.x;
|
|
640
|
+
res[5] = y.y;
|
|
667
641
|
res[6] = y.z;
|
|
642
|
+
res[8] = z.x;
|
|
643
|
+
res[9] = z.y;
|
|
668
644
|
res[10] = z.z;
|
|
669
645
|
/* eslint-enable prettier/prettier */
|
|
670
646
|
return res;
|
|
671
647
|
}
|
|
672
648
|
/**
|
|
673
|
-
* Returns a post-multiplied matrix.
|
|
649
|
+
* Returns a post-multiplied matrix equal to ab.
|
|
674
650
|
*/
|
|
675
651
|
function multiply$2(a, b) {
|
|
676
|
-
var
|
|
677
|
-
|
|
678
|
-
var
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
mat[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
|
693
|
-
mat[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
|
694
|
-
mat[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
|
695
|
-
mat[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
|
696
|
-
mat[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
|
697
|
-
mat[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
|
698
|
-
mat[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
|
699
|
-
mat[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
|
700
|
-
mat[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
|
701
|
-
mat[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
|
702
|
-
mat[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
|
703
|
-
return mat;
|
|
652
|
+
var result = makeIdentity();
|
|
653
|
+
// Consider each row i in the final matrix
|
|
654
|
+
for (var i = 0; i < 4; i++) {
|
|
655
|
+
// Consider each column j in the final matrix
|
|
656
|
+
for (var j = 0; j < 4; j++) {
|
|
657
|
+
// Calculate the value at row i and column j
|
|
658
|
+
var value = 0;
|
|
659
|
+
for (var k = 0; k < 4; k++) {
|
|
660
|
+
// Calculate (ik + kj) and add it to the value
|
|
661
|
+
value += a[i * 4 + k] * b[k * 4 + j];
|
|
662
|
+
}
|
|
663
|
+
var positionInResultingMatrix = 4 * i + j;
|
|
664
|
+
result[positionInResultingMatrix] = value;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return result;
|
|
704
668
|
}
|
|
705
669
|
/**
|
|
706
670
|
* Returns the [transpose](https://en.wikipedia.org/wiki/Transpose) of the given
|
|
@@ -717,32 +681,37 @@ function transpose(matrix) {
|
|
|
717
681
|
/* eslint-enable prettier/prettier */
|
|
718
682
|
}
|
|
719
683
|
/**
|
|
720
|
-
* Multiplies the columns of a matrix by the given vector.
|
|
684
|
+
* Multiplies the columns of a row-major matrix by the given vector.
|
|
721
685
|
*/
|
|
722
686
|
function scale$4(matrix, scale) {
|
|
723
687
|
var x = scale.x, y = scale.y, z = scale.z;
|
|
724
688
|
var m = __spreadArray([], matrix, true);
|
|
725
689
|
/* eslint-disable prettier/prettier */
|
|
726
690
|
m[0] *= x;
|
|
727
|
-
m[4] *= y;
|
|
728
|
-
m[8] *= z;
|
|
729
691
|
m[1] *= x;
|
|
730
|
-
m[5] *= y;
|
|
731
|
-
m[9] *= z;
|
|
732
692
|
m[2] *= x;
|
|
733
|
-
m[6] *= y;
|
|
734
|
-
m[10] *= z;
|
|
735
693
|
m[3] *= x;
|
|
694
|
+
m[4] *= y;
|
|
695
|
+
m[5] *= y;
|
|
696
|
+
m[6] *= y;
|
|
736
697
|
m[7] *= y;
|
|
698
|
+
m[8] *= z;
|
|
699
|
+
m[9] *= z;
|
|
700
|
+
m[10] *= z;
|
|
737
701
|
m[11] *= z;
|
|
738
702
|
/* eslint-enable prettier/prettier */
|
|
739
703
|
return m;
|
|
740
704
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
705
|
+
/**
|
|
706
|
+
* Sets the position of the matrix given as the first parameter
|
|
707
|
+
* to the position of the matrix given as the second parameter.
|
|
708
|
+
* Both matrices should have row-major format.
|
|
709
|
+
*/
|
|
710
|
+
function position(originalMatrix, matrixWithDesiredPosition) {
|
|
711
|
+
var m = __spreadArray([], originalMatrix, true);
|
|
712
|
+
m[12] = matrixWithDesiredPosition[12];
|
|
713
|
+
m[13] = matrixWithDesiredPosition[13];
|
|
714
|
+
m[14] = matrixWithDesiredPosition[14];
|
|
746
715
|
return m;
|
|
747
716
|
}
|
|
748
717
|
/**
|
|
@@ -754,8 +723,18 @@ function isIdentity(matrix) {
|
|
|
754
723
|
}
|
|
755
724
|
/**
|
|
756
725
|
* Returns an object representation of a `Matrix4`.
|
|
726
|
+
* @param m A Matrix4 item written in column-major form.
|
|
727
|
+
*
|
|
728
|
+
* @deprecated Use {@link toObjectColumnMajor} or {@link toObjectRowMajor} instead.
|
|
757
729
|
*/
|
|
758
730
|
function toObject(m) {
|
|
731
|
+
return toObjectColumnMajor(m);
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Returns an object representation of a `Matrix4`.
|
|
735
|
+
* @param m A Matrix4 item written in column-major form.
|
|
736
|
+
*/
|
|
737
|
+
function toObjectColumnMajor(m) {
|
|
759
738
|
/* eslint-disable prettier/prettier */
|
|
760
739
|
return {
|
|
761
740
|
m11: m[0], m12: m[4], m13: m[8], m14: m[12],
|
|
@@ -765,6 +744,20 @@ function toObject(m) {
|
|
|
765
744
|
};
|
|
766
745
|
/* eslint-enable prettier/prettier */
|
|
767
746
|
}
|
|
747
|
+
/**
|
|
748
|
+
* Returns an object representation of a `Matrix4`.
|
|
749
|
+
* @param m A Matrix4 item written in row-major form.
|
|
750
|
+
*/
|
|
751
|
+
function toObjectRowMajor(m) {
|
|
752
|
+
/* eslint-disable prettier/prettier */
|
|
753
|
+
return {
|
|
754
|
+
m11: m[0], m12: m[1], m13: m[2], m14: m[3],
|
|
755
|
+
m21: m[4], m22: m[5], m23: m[6], m24: m[7],
|
|
756
|
+
m31: m[8], m32: m[9], m33: m[10], m34: m[11],
|
|
757
|
+
m41: m[12], m42: m[13], m43: m[14], m44: m[15],
|
|
758
|
+
};
|
|
759
|
+
/* eslint-enable prettier/prettier */
|
|
760
|
+
}
|
|
768
761
|
/**
|
|
769
762
|
* A type guard to check if `obj` is of type `Matrix4`.
|
|
770
763
|
*/
|
|
@@ -788,7 +781,6 @@ var matrix4 = /*#__PURE__*/Object.freeze({
|
|
|
788
781
|
makeOrthographic: makeOrthographic,
|
|
789
782
|
makePerspective: makePerspective,
|
|
790
783
|
makeRotation: makeRotation,
|
|
791
|
-
makeRotationAxis: makeRotationAxis,
|
|
792
784
|
makeScale: makeScale,
|
|
793
785
|
makeTRS: makeTRS,
|
|
794
786
|
makeTranslation: makeTranslation,
|
|
@@ -797,6 +789,8 @@ var matrix4 = /*#__PURE__*/Object.freeze({
|
|
|
797
789
|
position: position,
|
|
798
790
|
scale: scale$4,
|
|
799
791
|
toObject: toObject,
|
|
792
|
+
toObjectColumnMajor: toObjectColumnMajor,
|
|
793
|
+
toObjectRowMajor: toObjectRowMajor,
|
|
800
794
|
transpose: transpose
|
|
801
795
|
});
|
|
802
796
|
|
|
@@ -847,9 +841,12 @@ function fromDegrees(value) {
|
|
|
847
841
|
* @param matrix A pure rotation matrix, unscaled.
|
|
848
842
|
* @param order The order that the rotations are applied.
|
|
849
843
|
*/
|
|
850
|
-
function fromRotationMatrix(matrix, order) {
|
|
844
|
+
function fromRotationMatrix(matrix, order, matrixIsColumnMajor) {
|
|
851
845
|
if (order === void 0) { order = 'xyz'; }
|
|
852
|
-
|
|
846
|
+
if (matrixIsColumnMajor === void 0) { matrixIsColumnMajor = true; }
|
|
847
|
+
var m = matrixIsColumnMajor
|
|
848
|
+
? toObjectColumnMajor(matrix)
|
|
849
|
+
: toObjectRowMajor(matrix);
|
|
853
850
|
var x = 0, y = 0, z = 0;
|
|
854
851
|
if (order === 'xyz') {
|
|
855
852
|
y = Math.asin(clamp(m.m13, -1, 1));
|
|
@@ -1028,55 +1025,47 @@ function fromAxisAngle(axis, radians) {
|
|
|
1028
1025
|
* (unscaled).
|
|
1029
1026
|
*/
|
|
1030
1027
|
function fromMatrixRotation(matrix) {
|
|
1031
|
-
|
|
1028
|
+
// Determine the scalars for each vector
|
|
1032
1029
|
var scale = fromMatrixScale(matrix);
|
|
1033
|
-
var
|
|
1034
|
-
|
|
1035
|
-
var
|
|
1036
|
-
var
|
|
1037
|
-
var
|
|
1038
|
-
var sm13 = m.m31 * is3;
|
|
1039
|
-
var sm21 = m.m12 * is1;
|
|
1040
|
-
var sm22 = m.m22 * is2;
|
|
1041
|
-
var sm23 = m.m32 * is3;
|
|
1042
|
-
var sm31 = m.m13 * is1;
|
|
1043
|
-
var sm32 = m.m23 * is2;
|
|
1044
|
-
var sm33 = m.m33 * is3;
|
|
1045
|
-
var trace = sm11 + sm22 + sm33;
|
|
1030
|
+
var oneOverScaleVector = create$a(1 / scale.x, 1 / scale.y, 1 / scale.z);
|
|
1031
|
+
// Scale the matrix
|
|
1032
|
+
var scaledMatrix = scale$4(matrix, oneOverScaleVector);
|
|
1033
|
+
var sM = toObjectRowMajor(scaledMatrix);
|
|
1034
|
+
var trace = sM.m11 + sM.m22 + sM.m33;
|
|
1046
1035
|
if (trace > 0) {
|
|
1047
|
-
var s = Math.sqrt(trace + 1
|
|
1036
|
+
var s = Math.sqrt(trace + 1) * 2;
|
|
1048
1037
|
return {
|
|
1049
|
-
x: (
|
|
1050
|
-
y: (
|
|
1051
|
-
z: (
|
|
1038
|
+
x: (sM.m23 - sM.m32) / s,
|
|
1039
|
+
y: (sM.m31 - sM.m13) / s,
|
|
1040
|
+
z: (sM.m12 - sM.m21) / s,
|
|
1052
1041
|
w: 0.25 * s,
|
|
1053
1042
|
};
|
|
1054
1043
|
}
|
|
1055
|
-
else if (
|
|
1056
|
-
var s = Math.sqrt(1
|
|
1044
|
+
else if (sM.m11 > sM.m22 && sM.m11 > sM.m33) {
|
|
1045
|
+
var s = Math.sqrt(1 + sM.m11 - sM.m22 - sM.m33) * 2;
|
|
1057
1046
|
return {
|
|
1058
1047
|
x: 0.25 * s,
|
|
1059
|
-
y: (
|
|
1060
|
-
z: (
|
|
1061
|
-
w: (
|
|
1048
|
+
y: (sM.m12 + sM.m21) / s,
|
|
1049
|
+
z: (sM.m31 + sM.m13) / s,
|
|
1050
|
+
w: (sM.m23 - sM.m32) / s,
|
|
1062
1051
|
};
|
|
1063
1052
|
}
|
|
1064
|
-
else if (
|
|
1065
|
-
var s = Math.sqrt(1
|
|
1053
|
+
else if (sM.m22 > sM.m33) {
|
|
1054
|
+
var s = Math.sqrt(1 + sM.m22 - sM.m11 - sM.m33) * 2;
|
|
1066
1055
|
return {
|
|
1067
|
-
x: (
|
|
1056
|
+
x: (sM.m12 + sM.m21) / s,
|
|
1068
1057
|
y: 0.25 * s,
|
|
1069
|
-
z: (
|
|
1070
|
-
w: (
|
|
1058
|
+
z: (sM.m23 + sM.m32) / s,
|
|
1059
|
+
w: (sM.m31 - sM.m13) / s,
|
|
1071
1060
|
};
|
|
1072
1061
|
}
|
|
1073
1062
|
else {
|
|
1074
|
-
var s = Math.sqrt(1
|
|
1063
|
+
var s = Math.sqrt(1 + sM.m33 - sM.m11 - sM.m22) * 2;
|
|
1075
1064
|
return {
|
|
1076
|
-
x: (
|
|
1077
|
-
y: (
|
|
1065
|
+
x: (sM.m31 + sM.m13) / s,
|
|
1066
|
+
y: (sM.m23 + sM.m32) / s,
|
|
1078
1067
|
z: 0.25 * s,
|
|
1079
|
-
w: (
|
|
1068
|
+
w: (sM.m12 - sM.m21) / s,
|
|
1080
1069
|
};
|
|
1081
1070
|
}
|
|
1082
1071
|
}
|
|
@@ -1216,19 +1205,19 @@ function isZeroVector(_a) {
|
|
|
1216
1205
|
* Returns a vector representing the scale elements of `matrix`.
|
|
1217
1206
|
*/
|
|
1218
1207
|
function fromMatrixScale(matrix) {
|
|
1219
|
-
var m =
|
|
1208
|
+
var m = toObjectRowMajor(matrix);
|
|
1220
1209
|
return {
|
|
1221
|
-
x: Math.hypot(m.m11, m.
|
|
1222
|
-
y: Math.hypot(m.
|
|
1223
|
-
z: Math.hypot(m.
|
|
1210
|
+
x: Math.hypot(m.m11, m.m12, m.m13),
|
|
1211
|
+
y: Math.hypot(m.m21, m.m22, m.m23),
|
|
1212
|
+
z: Math.hypot(m.m31, m.m32, m.m33),
|
|
1224
1213
|
};
|
|
1225
1214
|
}
|
|
1226
1215
|
/**
|
|
1227
1216
|
* Returns a vector representing the position elements of `matrix`.
|
|
1228
1217
|
*/
|
|
1229
1218
|
function fromMatrixPosition(matrix) {
|
|
1230
|
-
var m =
|
|
1231
|
-
return { x: m.
|
|
1219
|
+
var m = toObjectRowMajor(matrix);
|
|
1220
|
+
return { x: m.m41, y: m.m42, z: m.m43 };
|
|
1232
1221
|
}
|
|
1233
1222
|
/**
|
|
1234
1223
|
* Parses a JSON string representation of a Vector3 and returns an object.
|
|
@@ -1426,7 +1415,7 @@ function eulerTo(a, b) {
|
|
|
1426
1415
|
return dotAB > 1 - 1e-6 ? create$c() : create$c({ x: Math.PI });
|
|
1427
1416
|
}
|
|
1428
1417
|
var normalizedQ = normalize$1(create$b(__assign({ w: 1 + dotAB }, cross(normalizedA, normalizedB))));
|
|
1429
|
-
return fromRotationMatrix(makeRotation(normalizedQ));
|
|
1418
|
+
return fromRotationMatrix(makeRotation(normalizedQ), 'xyz', false);
|
|
1430
1419
|
}
|
|
1431
1420
|
/**
|
|
1432
1421
|
* Performs a projection of a `vector` onto `onNormal`.
|
|
@@ -1478,9 +1467,21 @@ function rotateAboutAxis(angle, point, axisDirection, axisPosition) {
|
|
|
1478
1467
|
}
|
|
1479
1468
|
}
|
|
1480
1469
|
/**
|
|
1481
|
-
* Returns a vector that is multiplied with a matrix.
|
|
1470
|
+
* Returns a vector that is multiplied with a matrix in column-major form.
|
|
1471
|
+
* @param vector A Vector3 item.
|
|
1472
|
+
* @param m A Matrix4 item written in column-major form.
|
|
1473
|
+
*
|
|
1474
|
+
* @deprecated Use {@link multiplyByTransformMatrixColumnMajor} or {@link multiplyByTransformMatrixRowMajor} instead.
|
|
1482
1475
|
*/
|
|
1483
1476
|
function transformMatrix$1(vector, m) {
|
|
1477
|
+
return multiplyByTransformMatrixColumnMajor(vector, m);
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Returns a vector that is multiplied with a matrix in column-major form.
|
|
1481
|
+
* @param vector A Vector3 item.
|
|
1482
|
+
* @param m A Matrix4 item written in column-major form.
|
|
1483
|
+
*/
|
|
1484
|
+
function multiplyByTransformMatrixColumnMajor(vector, m) {
|
|
1484
1485
|
var x = vector.x, y = vector.y, z = vector.z;
|
|
1485
1486
|
var w = 1 / (m[3] * x + m[7] * y + m[11] * z + m[15]);
|
|
1486
1487
|
return {
|
|
@@ -1489,6 +1490,20 @@ function transformMatrix$1(vector, m) {
|
|
|
1489
1490
|
z: (m[2] * x + m[6] * y + m[10] * z + m[14]) * w,
|
|
1490
1491
|
};
|
|
1491
1492
|
}
|
|
1493
|
+
/**
|
|
1494
|
+
* Returns a vector that is multiplied with a matrix in row-major form.
|
|
1495
|
+
* @param vector A Vector3 item.
|
|
1496
|
+
* @param m A Matrix4 item written in row-major form.
|
|
1497
|
+
*/
|
|
1498
|
+
function multiplyByTransformMatrixRowMajor(vector, m) {
|
|
1499
|
+
var x = vector.x, y = vector.y, z = vector.z;
|
|
1500
|
+
var w = 1 / (m[12] * x + m[13] * y + m[14] * z + m[15]);
|
|
1501
|
+
return {
|
|
1502
|
+
x: (m[0] * x + m[1] * y + m[2] * z + m[3]) * w,
|
|
1503
|
+
y: (m[4] * x + m[5] * y + m[6] * z + m[7]) * w,
|
|
1504
|
+
z: (m[8] * x + m[9] * y + m[10] * z + m[11]) * w,
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1492
1507
|
/**
|
|
1493
1508
|
* Euclidean distance between two vectors
|
|
1494
1509
|
*/
|
|
@@ -1552,7 +1567,7 @@ function lerp(a, b, t) {
|
|
|
1552
1567
|
* @returns A point in world space coordinates.
|
|
1553
1568
|
*/
|
|
1554
1569
|
function transformNdcToWorldSpace(ndc, worldMatrix, projectionMatrixInverse) {
|
|
1555
|
-
return
|
|
1570
|
+
return multiplyByTransformMatrixColumnMajor(multiplyByTransformMatrixColumnMajor(ndc, projectionMatrixInverse), worldMatrix);
|
|
1556
1571
|
}
|
|
1557
1572
|
|
|
1558
1573
|
var vector3 = /*#__PURE__*/Object.freeze({
|
|
@@ -1582,6 +1597,8 @@ var vector3 = /*#__PURE__*/Object.freeze({
|
|
|
1582
1597
|
max: max,
|
|
1583
1598
|
min: min,
|
|
1584
1599
|
multiply: multiply,
|
|
1600
|
+
multiplyByTransformMatrixColumnMajor: multiplyByTransformMatrixColumnMajor,
|
|
1601
|
+
multiplyByTransformMatrixRowMajor: multiplyByTransformMatrixRowMajor,
|
|
1585
1602
|
negate: negate,
|
|
1586
1603
|
normalize: normalize,
|
|
1587
1604
|
origin: origin,
|
|
@@ -2089,8 +2106,8 @@ function center(line) {
|
|
|
2089
2106
|
* @returns A transformed line.
|
|
2090
2107
|
*/
|
|
2091
2108
|
function transformMatrix(line, matrix) {
|
|
2092
|
-
var start =
|
|
2093
|
-
var end =
|
|
2109
|
+
var start = multiplyByTransformMatrixColumnMajor(line.start, matrix);
|
|
2110
|
+
var end = multiplyByTransformMatrixColumnMajor(line.end, matrix);
|
|
2094
2111
|
return { start: start, end: end };
|
|
2095
2112
|
}
|
|
2096
2113
|
/**
|