Currently, I am working on a project involving an application that showcases various 3D models. The process involves loading the models, creating meshes, and adding them to the scene as part of the standard procedure. Upon completing the addition of the last mesh, we compute the bounding box to adjust the camera position in order to encompass the entire scene. This calculation takes into account both the total geometry size and the viewport dimensions.
if (bounds.bx / bounds.by < camera.aspect) {
/* Vertical maximum */
r = bounds.by / (2 * Math.tan(Math.PI / 8));
} else {
/* Horizontal maximum */
hFOV = 2 * Math.atan(Math.tan(Math.PI / 8) * camera.aspect);
r = bounds.bx / (2 * Math.tan((hFOV / 2)));
}
The object bounds
stores the width and height of the bounding box. Following this computation, we adjust the camera position with a small additional ratio for aesthetic purposes, providing some space between the geometry and the screen border before rendering.
camera.position.z = r * 1.05;
Although this implementation works smoothly with the PerspectiveCamera, our team is looking to transition to using the OrthographicCamera. However, this shift has proven challenging. The models appear too small, the mousewheel zoom functionality from the TrackBall Controls is lost, and the camera relocation algorithm no longer functions as expected. Additionally, there is confusion regarding the constructor parameters for the camera - are the width and height specified intended for the geometry or the viewport?