Created
November 15, 2017 11:20
-
-
Save Strae/7def0f84677e03727f771636709b448f to your computer and use it in GitHub Desktop.
Aframe entity in viewport / visible
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
//RETURNS TRUE/FALSE BASED ON WHETHER OR NOT THE ENTITY IS VISIBLE | |
checkIfVisible(entity, camera){ | |
let entityMesh = entity.object3DMap.mesh; | |
let frustum = new THREE.Frustum(); | |
let cameraViewProjectionMatrix = new THREE.Matrix4(); | |
camera.updateMatrixWorld(); | |
camera.matrixWorldInverse.getInverse(camera.matrixWorld); | |
cameraViewProjectionMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse); | |
frustum.setFromMatrix(cameraViewProjectionMatrix); | |
return frustum.intersectsObject(entityMesh); | |
}//checkIfVisible | |
// @source https://aframevr.slack.com/files/U2R8WNPL6/F80KA30LA/check_if_entity_is_in_the_viewport.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment