Jump to content

[SOLVED] Determine camera distance to make mesh fit


ozRocker
 Share

Recommended Posts

I'm wondering if there's a way I can determine the Y position of a camera so the mesh its looking at completely fills the viewport.  Basically I have a camera above the ground which is looking down to the ground at a 45 degree angle and is focusing on certain objects on the ground.  Is this possible?

 

Link to comment
Share on other sites

On 30/06/2017 at 2:15 PM, sable said:

My example uses boundingSphere instead, which I think should exist in 2.5 as well.

Using the sphere means that any rotation of the mesh you're focusing on should fit in the viewport.

Thank you!  I couldn't get it working then I realised that mesh scale needs to be 1, so once I got that sorted it worked perfectly :)

Link to comment
Share on other sites

I have a mesh that only rotates around the Y-axis so I found that boundingSphere is too restrictive because it checks on every axis.  Is there a way to use a bounding sphere (or maybe bounding cylinder) for this kind of situation.  At the moment the mesh ends up a bit too small with some space around it

Link to comment
Share on other sites

Use a bounding box instead of a sphere then, find the axis with the longest measurement.  

When I get home I'll show you the way I did it for a client.  This is fairly simple to do without the preview version of bjs

Link to comment
Share on other sites

24 minutes ago, Pryme8 said:

Use a bounding box instead of a sphere then, find the axis with the longest measurement.  

When I get home I'll show you the way I did it for kirakira.  This is fairly simple to do without the preview version of bjs

I'm trying to steer clear of the preview version 'cos of the broken inspector but I'll use it if I absolutely have to.

But I'm wondering if a bounding box will work.  The point of the bounding sphere was that it works on all rotations.  A bounding box calculation will cause the mesh to go out of the viewport on its diagonals like in this example https://www.babylonjs-playground.com/#P6JAWE#6 (if you rotate by hand the diagonals will bust out of the viewport)

A bounding cylinder would be perfect because that would calculate only on the Y-axis rotation.

 

 

Link to comment
Share on other sites

I thought I had it then I ran tests, give me a second.
https://www.babylonjs-playground.com/#P6JAWE#7

this does not work fully yet, I did not have much time to look at it though.

https://www.babylonjs-playground.com/#P6JAWE#9
there we go I think this may work...
@ozRocker

https://www.babylonjs-playground.com/#P6JAWE#10

This shows it pushed to the extreme, I tried both orientations and it seems to work have not tested any with y height yet. maybe switch from a ground to a cube.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...