Translation Issue? 4x4 Transformation Matrix "flattening" 3d model

Hi all, so I have a series of vertices stored in a BufferAttribute in which I need to translate 100 units on the z axis. I see that there’s an applyMatrix4 method in which I can apply a 4x4 transformation matrix to accomplish exactly this. I apply the matrix, which seems to correctly shift my 3d Model, but then flattens it.

Before

After [Shifted correctly, but flattened]

Here’s my code, if that helps. Thanks.

let origins = loadedGeometry.attributes.position.clone();
const m = new THREE.Matrix4();
m.set(1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 100, 0, 0, 0, 1);
origins.applyMatrix4(m);

[SOLVED]
Ah, my transformation matrix had the 0’s and 1’s in the wrong places. Haha thanks all!

BufferAttribute has .applyMatrix4() method, that calls vector.applyMatrix4() internally.
And for Vector3, .applyMatrix4() docs say:
Multiplies this vector (with an implicit 1 in the 4th dimension) and m, and divides by perspective.
So, there shouldn’t be a problem with applying Matrix4 on a buffer attribute with 3 components per item. :thinking:

1 Like

Oh I think you’re right. It is translating correctly, so it must be something else causing the strange behavior. I’ve updated the post, thanks.

Why not try:

const m = new THREE.Matrix4().setPosition(0, 0, 100);
origins.applyMatrix4(m);
1 Like