I've been experimenting with Three.js and have a canvas that I want to use as a GUI. To achieve this, I need to check if an object is within the camera's frustum.
Here is my current code snippet:
camera.updateMatrix();
camera.updateMatrixWorld();
const frustum = new THREE.Frustum();
const projScreenMatrix = new THREE.Matrix4();
projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
frustum.setFromProjectionMatrix( camera.projectionMatrix );
if(frustum.containsPoint( mesh.position )){
// do something...
};
The issue I'm facing is that frustum.containsPoint()
keeps returning false
. Any suggestions on what might be going wrong here?