Hi All
Is there a way to calculate the camera’s fov so that the camera view fits to object dimension and canvas size ?
I found a way to make the fov camera adjust to the size of the object in this forum:
Hi all,
Is there a way to calculate the camera’s fov so that the camera view fits the size of the object?
This is my PG: Babylon.js Playground
I made a sample code where I created a box and then I positioned the camera very close to the box, after that I set the camera’s fov value (set manually) so that all parts of the object can be seen. but I want the camera’s fov value to adjust based on the size of the box, until the box looks ideal (not too close and not too far)
But I want the fov camera to be able to adjust to the canvas size too. because my project requires that it can run on all devices
This is the PG: https://playground.babylonjs.com/#Y82BS8#3
1 Like
Blake
November 12, 2021, 5:50am
2
Hey there, one way to do this is to use an ArcRotateCamera, which has framing behavior available. :
https://playground.babylonjs.com/#5T0H6Q#2
Edit: IDK if you want it re-adjust on resizing or just once at the start, but if you want it on resizing it looks like @roland ’s got you covered.
2 Likes
roland
November 12, 2021, 6:01am
3
Hi! I’ve created this small PG, but @Blake was faster.
https://playground.babylonjs.com/#Y82BS8#5
2 Likes
but i need the fov value and i use free camera, for some reason i can’t use ArcRotateCamera camera
roland
November 12, 2021, 6:26am
5
My PG shows how to use the world extends. Or you can use the boundigInfo of the mesh. Look at the API. You basically get the max and min values out of it. You can calculate the fov from these values accordingly.
could you give me some sample please ?
roland
November 12, 2021, 7:05am
7
You can change the size of the sphere and the size
variable will change accordingly. You can use whatever mesh you want.
https://playground.babylonjs.com/#4F33I3#397
Check the docs:
1 Like
roland
November 12, 2021, 7:21am
8
Do you need more detailed help?
thank @roland , i will try to implement it
1 Like
Hi @Muhamad_Rifky just checking in, did you get the fov working like you wanted?