brand banner

Object Geometry (Vertices) and World Matrix

Explains how Object3D.applyMatrix4() in Three.js modifies an object's geometry directly without affecting its world matrix, and clarifies the difference between local transformations and world-space transformations.

Updated · 5 min read · #threejs · #programming

Object Geometry (Vertices) and World Matrix

Explains how Object3D.applyMatrix4() in Three.js modifies an object's geometry directly without affecting its world matrix, and clarifies the difference between local transformations and world-space transformations.

❓ 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()?

  • It directly applies the transformation (scaling, rotation, or translation) to the object’s geometry.
  • The object’s local vertex positions are permanently changed.
  • The world matrix (object.matrixWorld) remains unchanged because the transformation is “baked” into the geometry itself.

📌 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,
);
  • The geometry changes (vertices are modified).
  • The world matrix remains the same (no change in cube.matrixWorld unless updateMatrixWorld() is manually called).

📌 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 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!

📌 When 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.


📌 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

  • Local space (or object space) is the coordinate system relative to the object’s own origin, which is (0, 0, 0) unless explicitly transformed.
  • World space is the global coordinate system that takes into account the transformations (position, rotation, scale) of all parent objects in the hierarchy.

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:

  • World matrix is a combination of all transformations (position, rotation, scale) applied by all parents.
  • When applying a transformation using 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.

📌 Why Does applyMatrix4() Scale From World Matrix?

  • Hierarchical transformations: When you apply a matrix to an object, the object’s local transformations are applied relative to its world space (taking into account its position, rotation, and scale relative to its parent objects).
  • It modifies the geometry: 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.

📌 Summary

  • 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.
  • This is different from using 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.


© 2026 James Yap

Personal Website and Knowledge Base