@@ -55,6 +55,29 @@ export class Matrix extends MatrixInterface {
5555 }
5656 }
5757
58+ /**
59+ * Sets the values of this 3×3 matrix.
60+ *
61+ * This copies the 9 provided numeric components into the internal
62+ * `Float32Array` without replacing the underlying buffer.
63+ *
64+ * @param {ArrayLike<number> } values -
65+ * Array-like object with 9 numeric components, in column-major order.
66+ * @throws {Error } If the matrix is not 3×3.
67+ * @throws {Error } If `values` is not array-like or does not contain 9 items.
68+ */
69+ set mat3 ( values ) {
70+ if ( this . #sqDimention !== 3 ) {
71+ throw new Error ( 'mat3 setter is only valid for 3×3 matrices.' ) ;
72+ }
73+ if ( ! values || typeof values . length !== 'number' || values . length !== 9 ) {
74+ throw new Error ( 'mat3 setter expects an array-like of length 9.' ) ;
75+ }
76+ for ( let i = 0 ; i < 9 ; i ++ ) {
77+ this . matrix [ i ] = values [ i ] ;
78+ }
79+ }
80+
5881 /**
5982 * Returns the 4x4 matrix if the dimensions are 4x4, otherwise returns `undefined`.
6083 *
@@ -71,6 +94,37 @@ export class Matrix extends MatrixInterface {
7194 }
7295 }
7396
97+ /**
98+ * Sets the values of this 4×4 matrix.
99+ *
100+ * This setter accepts an array-like object of length 16 and copies its
101+ * contents into the internal `Float32Array` used to represent the matrix.
102+ *
103+ * Note that this does **not** replace the underlying buffer; it only
104+ * overwrites the existing values.
105+ *
106+ * ```js
107+ * // Copy another matrix's data
108+ * M.mat4 = other.mat4.slice();
109+ * ```
110+ *
111+ * @param {ArrayLike<number> } values -
112+ * Array-like object with 16 numeric components, in column-major order.
113+ * @throws {Error } If the matrix is not 4×4.
114+ * @throws {Error } If `values` is not array-like or does not contain 16 items.
115+ */
116+ set mat4 ( values ) {
117+ if ( this . #sqDimention !== 4 ) {
118+ throw new Error ( 'mat4 setter is only valid for 4x4 matrices.' ) ;
119+ }
120+ if ( ! values || typeof values . length !== 'number' || values . length !== 16 ) {
121+ throw new Error ( 'mat4 setter expects an array-like of length 16.' ) ;
122+ }
123+ for ( let i = 0 ; i < 16 ; i ++ ) {
124+ this . matrix [ i ] = values [ i ] ;
125+ }
126+ }
127+
74128 /**
75129 * Adds the corresponding elements of the given matrix to this matrix, if the dimentions are the same.
76130 *
0 commit comments