It is essential to be accurate in this situation.
To determine the visible rectangular area based on the camera's field-of-view, camera.fov
, and a specified distance, dist
, from the camera.
Considering that the object likely has depth, you must select one plane within the mesh and perform the calculation at that specific distance.
Here is the method to compute the visible height
and width
for a given distance of dist
from the camera.
const verticalFOV = THREE.MathUtils.degToRad( camera.fov ); // converting vertical fov to radians
const visibilityHeight = 2 * Math.tan( verticalFOV / 2 ) * dist; // visible height
const visibilityWidth = visibilityHeight * camera.aspect; // visible width
UPDATE: A new built-in function is now accessible: PerspectiveCamera.getViewSize()
:
const targetAngle = new THREE.Vector2(); // create once and reuse it
camera.getViewSize( distance, targetAngle ); // the output will be saved in targetAngle
three.js r162