@@ -25,7 +25,9 @@ import { QuatArg } from './quat';
25
25
import { Mat3Arg , Mat3Type } from './mat3' ;
26
26
import { Mat4Arg } from './mat4' ;
27
27
import { Vec2Arg } from './vec2' ;
28
+ import { Vec3Arg } from './vec3' ;
28
29
import { getAPI as getVec2API } from './vec2-impl' ;
30
+ import { getAPI as getVec3API } from './vec3-impl' ;
29
31
import { BaseArgType } from './types' ;
30
32
31
33
export { Mat3Arg , Mat3Type } ;
@@ -37,6 +39,7 @@ type Mat3Ctor<T extends Mat3Arg = Float32Array> = new (n: number) => T;
37
39
* */
38
40
function getAPIImpl < MatType extends Mat3Arg = Float32Array > ( Ctor : Mat3Ctor < MatType > ) {
39
41
const vec2 = getVec2API < MatType > ( Ctor ) ;
42
+ const vec3 = getVec3API < MatType > ( Ctor ) ;
40
43
41
44
/**
42
45
* Create a Mat3 from values
@@ -502,11 +505,11 @@ function setAxis<T extends Mat3Arg = MatType>(m: Mat3Arg, v: Vec2Arg, axis: numb
502
505
return newDst ;
503
506
}
504
507
505
- /// **
506
- // * Returns the scaling component of the matrix
507
- // * @param m - The Matrix
508
- // * @param dst - The vector to set. If not passed a new one is created.
509
- // */
508
+ /**
509
+ * Returns the "2d" scaling component of the matrix
510
+ * @param m - The Matrix
511
+ * @param dst - The vector to set. If not passed a new one is created.
512
+ */
510
513
function getScaling < T extends Vec2Arg = MatType > ( m : Mat3Arg , dst ?: T ) {
511
514
const newDst = ( dst ?? vec2 . create ( ) ) ;
512
515
@@ -521,6 +524,32 @@ function getScaling<T extends Vec2Arg = MatType>(m: Mat3Arg, dst?: T) {
521
524
return newDst ;
522
525
}
523
526
527
+
528
+ /**
529
+ * Returns the "3d" scaling component of the matrix
530
+ * @param m - The Matrix
531
+ * @param dst - The vector to set. If not passed a new one is created.
532
+ */
533
+ function get3DScaling < T extends Vec3Arg = MatType > ( m : Mat3Arg , dst ?: T ) {
534
+ const newDst = ( dst ?? vec3 . create ( ) ) ;
535
+
536
+ const xx = m [ 0 ] ;
537
+ const xy = m [ 1 ] ;
538
+ const xz = m [ 2 ] ;
539
+ const yx = m [ 4 ] ;
540
+ const yy = m [ 5 ] ;
541
+ const yz = m [ 6 ] ;
542
+ const zx = m [ 8 ] ;
543
+ const zy = m [ 9 ] ;
544
+ const zz = m [ 10 ] ;
545
+
546
+ newDst [ 0 ] = Math . sqrt ( xx * xx + xy * xy + xz * xz ) ;
547
+ newDst [ 1 ] = Math . sqrt ( yx * yx + yy * yy + yz * yz ) ;
548
+ newDst [ 2 ] = Math . sqrt ( zx * zx + zy * zy + zz * zz ) ;
549
+
550
+ return newDst ;
551
+ }
552
+
524
553
/**
525
554
* Creates a 3-by-3 matrix which translates by the given vector v.
526
555
* @param v - The vector by which to translate.
@@ -750,6 +779,7 @@ return {
750
779
getAxis,
751
780
setAxis,
752
781
getScaling,
782
+ get3DScaling,
753
783
translation,
754
784
translate,
755
785
rotation,
0 commit comments