Matrix4
Quick answer
Matrix4 is a 4x4 column-major transform matrix holding translation, rotation, scale, and projection. Object3D uses it for matrix and matrixWorld, and you can compose transforms with compose(), invert() them, or build camera projections with makePerspective() and makeOrthographic(). elements stores 16 floats in column-major order, matching GPU upload layout.
new THREE.Matrix4 () → Matrix4(单位矩阵)
Key points
- compose(position, quaternion, scale) builds T * R * S and decompose() reverses it.
- multiply() applies its argument before the current matrix; premultiply() applies it after.
- set() takes row-major arguments and transposes internally.
Example
const m = new THREE.Matrix4();
const T = new THREE.Matrix4().makeTranslation(10, 0, 5);
const R = new THREE.Matrix4().makeRotationY(Math.PI / 6);
const S = new THREE.Matrix4().makeScale(2, 2, 2);
m.multiplyMatrices(T, R).multiply(S); // T · R · S
const position = new THREE.Vector3(10, 0, 5);
const quaternion = new THREE.Quaternion().setFromAxisAngle(
new THREE.Vector3(0, 1, 0), Math.PI / 6
);
m.compose(position, quaternion, new THREE.Vector3(2, 2, 2));mesh.updateMatrix();
const world = new THREE.Matrix4().multiplyMatrices(
mesh.parent ? mesh.parent.matrixWorld : new THREE.Matrix4(),
mesh.matrix
);
const clip = new THREE.Vector4(x, y, z, 1).applyMatrix4(camera.projectionMatrix);
const ndcX = clip.x / clip.w;
Notes
- makeTranslation() and makeScale() overwrite the matrix instead of accumulating onto it.
- Large world coordinates lose float precision; shift the scene toward the origin instead.
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Atlaslog (2026). Matrix4. https://www.jingweizhi.com/en/three/api/matrix4.html (accessed 2026-11-03).