Object Geometry (Vertices) and World Matrix

❓ Question: Does 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.


📌 What Happens When You Call applyMatrix4()?


📌 Confirming This in Code

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,
);

📌 Difference Between applyMatrix4() and Modifying scale

MethodModifies 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))

📌 Conclusion

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).


❓ Question: When Does matrixWorld Update?

The matrixWorld represents an object’s final transformation in world space, combining:

  1. position (translation)
  2. rotation
  3. scale
  4. Parent object transformations (if any)

It updates automatically under these conditions:


📌 When matrixWorld Stays the Same

If you call applyMatrix4(), the matrixWorld does not change immediately because:

If the object is static (no parent updates, no position/scale changes), matrixWorld remains unchanged.


📌 Force Updating 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.


📌 Summary

🔹 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).


📌 Local Space vs. World Space in Three.js

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.


📌 What Does 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:

  1. Transformation matrices (like scaling or translation) are created in local space.
  2. World matrix for an object (calculated using the object's transformations and its parents' transformations) represents the object's position in the world space.
  3. When you apply the transformation matrix via 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.

📌 Example: Understanding 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);

What happens:

  1. Parent has a position of (5, 5, 5) and is scaled by a factor of 2.
  2. When we apply the scaling matrix to the parent object, the child's geometry gets scaled in world space. This affects how the child is rendered relative to the parent's scale and position, since the matrix you apply is in world coordinates.

📌 Key Concepts for applyMatrix4() and World Space:


📌 Why Does applyMatrix4() Scale From World Matrix?


📌 Summary


© 2025 James Yap

Personal Website and Knowledge Base