Object3D.applyMatrix4()
change the geometry of the object or its world matrix?Applying a matrix with applyMatrix4(scalingMatrix)
modifies the geometry itself but does not modify the world matrix.
applyMatrix4()
?object.matrixWorld
) remains unchanged because the transformation is "baked" into the geometry itself.const cube = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0xff0000 }),
);
console.log("Before applying matrix:", cube.matrixWorld.clone());
const scalingMatrix = new THREE.Matrix4().makeScale(2, 2, 2);
cube.applyMatrix4(scalingMatrix);
console.log("After applying matrix:", cube.matrixWorld.clone());
console.log(
"Updated geometry vertices:",
cube.geometry.attributes.position.array,
);
cube.matrixWorld
unless updateMatrixWorld()
is manually called).applyMatrix4()
and Modifying scale
Method | Modifies Geometry? | Affects matrixWorld ? | Can Be Reset Easily? |
---|---|---|---|
applyMatrix4() | ✅ Yes (modifies vertex positions) | ❌ No (world matrix stays the same) | ❌ No (geometry is permanently changed) |
object.scale.set() | ❌ No (only changes transformation) | ✅ Yes (affects world matrix) | ✅ Yes (just reset scale.set(1,1,1) ) |
✅ applyMatrix4()
modifies geometry but not matrixWorld
.
✅ It "bakes" the transformation into vertex positions.
✅ The object's scale
, position
, and rotation
remain unchanged.
✅ If you want non-destructive scaling, use object.scale.set(x, y, z)
.
matrixWorld
Update?The matrixWorld
represents an object’s final transformation in world space, combining:
position
(translation)rotation
scale
It updates automatically under these conditions:
When position
, rotation
, or scale
change:
object.position.set(5, 0, 0);
console.log(object.matrixWorld); // This will update automatically
When updateMatrixWorld(true)
is called (manually recomputes matrixWorld
):
object.updateMatrixWorld(true);
If the object is part of a hierarchy, and a parent’s transformation changes:
parent.position.set(10, 0, 0);
console.log(child.matrixWorld); // Child's world position changes too!
matrixWorld
Stays the Same✅ If you call applyMatrix4()
, the matrixWorld
does not change immediately because:
applyMatrix4()
modifies the geometry directly, not the transformation properties (position
, scale
, rotation
).matrixWorld
will still represent the object's original world transformation, unless updated manually.✅ If the object is static (no parent updates, no position/scale changes), matrixWorld
remains unchanged.
matrixWorld
If you've applied a transformation and want to force update the matrixWorld
, do this:
object.updateMatrixWorld(true);
This ensures that any transformations (manual or inherited) are recalculated and applied correctly.
🔹 matrixWorld
updates automatically when position
, scale
, or rotation
change.
🔹 matrixWorld
does NOT change if you use applyMatrix4()
—because that affects geometry, not world transformation.
🔹 You can manually update it with updateMatrixWorld(true)
.
(0, 0, 0)
unless explicitly transformed.When you apply transformations using applyMatrix4()
, you’re dealing with world space transformations, which means applying a transformation matrix relative to the current object’s world coordinates.
applyMatrix4()
Do?applyMatrix4(matrix)
applies a transformation matrix (like scaling, rotation, or translation) directly to the object’s geometry in local space. The reason why it behaves as if scaling occurs in world space has to do with how the matrix is applied to the object's geometry.
Here’s what happens under the hood:
applyMatrix4()
, the matrix modifies the geometry relative to the object's world coordinates, not just the object's local space. This is because the geometry is scaled, rotated, and translated based on world space rather than just the object's local space.applyMatrix4()
Let’s say you have a parent object that has been scaled, and you apply applyMatrix4()
to a child object:
const parent = new THREE.Object3D();
const child = new THREE.Mesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({ color: 0xff0000 }),
);
// Position and scale the parent
parent.position.set(5, 5, 5);
parent.scale.set(2, 2, 2);
// Add the child to the parent
parent.add(child);
// Now we apply a scaling matrix to the parent
const scalingMatrix = new THREE.Matrix4().makeScale(2, 2, 2);
parent.applyMatrix4(scalingMatrix);
(5, 5, 5)
and is scaled by a factor of 2.applyMatrix4()
and World Space:applyMatrix4()
, you're essentially modifying the geometry of the object relative to world space, meaning the object’s final location and scale are based on the world coordinate system.applyMatrix4()
Scale From World Matrix?applyMatrix4()
directly alters the geometry of the object, so it’s scaled and transformed relative to the current world space. Even though the object’s position remains the same in world space, the geometry is affected by world coordinates.applyMatrix4()
scales an object relative to its world space because it modifies the object’s geometry based on the transformations that affect its position and orientation in world coordinates.scale.set()
or modifying the object’s scale
property, which only affects the local transformations and doesn’t directly modify geometry or the world matrix.© 2025 James Yap
Personal Website and Knowledge Base