How to dynamically adjust the camera in three js

One way to solve this issue is by changing camera parameters based on the bounding box of your mesh. This approach is used by viewer application like the three.js based gltf-viewer. Check out the following code listing for more information:

The code also centers the object which is probably not required in your scene.