How do i get positions of glb model descendants?

I have this glb model and i am trying to get the position of its descendants (i.e. by traversing the model), but the positions of all the meshes are returning the same position.

code:

model.updateMatrix()
model.updateMatrixWorld(true, true)
const meshPos = new THREE.Vector3();

model.traverse((mesh) => {
  if(mesh.isMesh) {
    mesh.getWorldPosition(meshPos);
    console.log(meshPos)
  }
})

you are logging the same vector instance, which gets overwritten for each mesh. when you open it in dev tools what you’ll find is the position of the last mesh.

const meshPos = mesh.getWorldPosition(new THREE.Vector3())
1 Like