Skip to content

Instantly share code, notes, and snippets.

@zentrope
Created January 18, 2015 17:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zentrope/5022d89cfa995ac71978 to your computer and use it in GitHub Desktop.
Save zentrope/5022d89cfa995ac71978 to your computer and use it in GitHub Desktop.
three.js detect off-screen objects?
var frustum = new THREE.Frustum();
var cameraViewProjectionMatrix = new THREE.Matrix4();
// every time the camera or objects change position (or every frame)
camera.updateMatrixWorld(); // make sure the camera matrix is updated
camera.matrixWorldInverse.getInverse( camera.matrixWorld );
cameraViewProjectionMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
frustum.setFromMatrix( cameraViewProjectionMatrix );
// frustum is now ready to check all the objects you need
console.log( frustum.intersectsObject( object ) );
// http://stackoverflow.com/questions/17624021/determine-if-a-mesh-is-visible-on-the-viewport-according-to-current-camera
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment