applyMatrix4() to bufferGeometry vs Object3d

Basically I wanted to translate the position of the gizmo line along axis X. When setting the following configuration over the mesh, the translation does not work:

Original Gizmo mesh:

enter image description here

for (const key in gizmo.translate.children) {
    const giz = gizmo.translate.children[key];
    if (giz.name === "X") {
      if (count === 0) {
        console.log(giz);

        giz.applyMatrix4(
          new THREE.Matrix4().makeTranslation(
            -0.5,
            0,
            0
          )
        );
        giz.updateMatrix();
      }

      count++;
    }
  }

however, when applying the translation over the bufferGeometry, it works:

let count = 0;
  for (const key in gizmo.translate.children) {
    const giz = gizmo.translate.children[key];
    if (giz.name === "X") {
      //0 is the arrow body
      if (count === 0) {
        giz.geometry.applyMatrix4(
          new THREE.Matrix4().makeTranslation(
            -0.5,
            0,
            0
          )
        );
        // giz.updateMatrix();
        // giz.visible = false;
        // giz.layers.disable(0);
      }

      count++;
    }
  }

enter image description here

Iā€™m confused about this, can someone make some clarifications about this behavior?

Without any code to test with, this is just a guess:

The matrix of an Object3D is automatically calculated from its position, quaternion/rotation. When you manually set the matrix, it is overwritten, so your changes are lost. To prevent this, you can:

  • either modify the position/quaternion/rotation (not the matrix)
  • or set matrixAutoUpdate to false and then apply your matrix

BufferGeometry does not act like this. When you apply a matrix, it modifies all vertices in the buffer.

2 Likes

interesting, I will try this. Keep you posted