0
$\begingroup$

I want to set a transformation matrix to an object upon creation and then control it by position, rotation and scale, but while changing the matrix does change the object in world space, it's position parameter still remains 0, 0, 0.

let mesh =  new THREE.Mesh(
    new THREE.BoxGeometry(),
    new THREE.MeshPhongMaterial({color:0xf15728})
)
this.scene.add(mesh)

let pos = new THREE.Vector3().setFromMatrixPosition(m)

mesh.matrixAutoUpdate = false
mesh.matrix.copy(m)

// ***************//
mesh.updateMatrix()
// ***************//

console.log("mesh.position", mesh.position)
console.log("pos", pos)

Here's the output for the values of both pos and mesh.position

enter image description here

$\endgroup$

1 Answer 1

0
$\begingroup$

I think you need to call setFromMatrixPosition(m) again after updating the matrix. After all, you need to update both the position and matrix, not just the matrix.

mesh.position.setFromMatrixPosition(mesh.matrix) or mesh.position = new THREE.Vector3().setFromMatrixPosition(mesh.matrix) right after mesh.updateMatrix()

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.