zMatrix()
使用此类型,你可以在 属性编辑器 中直观地编辑矩阵。
🌐 With this type, you can visually edit a matrix in the Props Editor.
矩阵必须是“平的”,例如一个2x2矩阵必须表示为一个由4个数字组成的数组:[0, 1, 1, 0]。
🌐 The matrix has to be "flat", for example a 2x2 matrix has to be represented as an array of 4 numbers: [0, 1, 1, 0].
矩阵必须是方阵,例如 2x2、3x3、4x4 等。
🌐 The matrix has to be a square matrix, for example a 2x2, 3x3, 4x4, etc.
const myCompSchema = z.object({
matrix: zMatrix(),
});
// Two-dimensional matrix
myCompSchema.parse({
matrix: [0, 1, 1, 0],
});
// Three-dimensional matrix
myCompSchema.parse({
matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
});
// Four-dimensional matrix
myCompSchema.parse({
matrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
});另请参阅
🌐 See also