How to make camera face a cube face on load on the page

Hi,I have a requirement where the camera should face at the face of the warehouse on the initial load of the page. But the issue is the warehouse structure can vary in structure Below is the attached images of three different projects This is a warehouse structure

I’m expected to display a zoomed version of this
enter image description here

i cannot hardcore the camera positions as the structure can vary for other projects. example
enter image description here

I was trying to adjust by using

camera.position.x =  -warehouse.geometry.parameters.depth/2;    
camera.position.y =  3;
camera.position.z = warehouse.geometry.parameters.width;

Can someone guide me how to resolve this issue. Thanks for your time

Have you tried to compute the AABB of your warehouse and then use it to configure the camera? This approach is often used by viewers, e.g.:

The object variable in line 266 would represent your warehouse mesh.


It was posted by me :slightly_smiling_face:

Hi Michael,
I tried using this method,but I’m getting the below error

I googled this but didnt get anything helpful

Do you have any idea abt this


Well, you probably have to add the THREE namespace. So new THREE.Box3().

Ahh ,I went through the error so many times.yet could not spot this.

Thanks Michael