Created
January 18, 2015 17:09
-
-
Save zentrope/5022d89cfa995ac71978 to your computer and use it in GitHub Desktop.
three.js detect off-screen objects?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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