Skip to content

Instantly share code, notes, and snippets.

@Strae
Created November 15, 2017 11:20
Show Gist options
  • Save Strae/7def0f84677e03727f771636709b448f to your computer and use it in GitHub Desktop.
Save Strae/7def0f84677e03727f771636709b448f to your computer and use it in GitHub Desktop.
Aframe entity in viewport / visible
//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