Jump to content

Getting viewport dimensions


brean
 Share

Recommended Posts

Hi,

I am building a openstreetmap-integration to Babylon.js and I like to only load tiles that need to be shown and dispose tiles that are not visible anymore.

To do that I need some way to figure out what tiles are in the view. I already found BABYLON.Vector3.Unproject which I could feed with the screen width/height divided by 2 in all directions to calculate the dimensions of the viewport in babylon coordinates.

I only manage to get this working when the camera is directly in front of the screen, so I need to figure out how the distance from the camera to the screen can be used, see: http://www.babylonjs-playground.com/#ZFXWSF

Can anyone tell me how I get the dimensions of the viewport at a cirtain distance in babylon coordinates?

Link to comment
Share on other sites

18 hours ago, brean said:

I am building a openstreetmap-integration to Babylon.js and I like to only load tiles that need to be shown and dispose tiles that are not visible anymore.

Hello.. this seems like a LOD problem (https://doc.babylonjs.com/how_to/how_to_use_lod), but based on your post,  you can also try isInFrustum method.
Few PGs that are already available https://www.babylonjs-playground.com/#12D0ST#1https://www.babylonjs-playground.com/#050P3M#1

EDIT: If I am not wrong, then viewport would be constant irrespective of camera's movement.. but again, I am not sure. Maybe someone from core team should be able to answer. 😅😅

Link to comment
Share on other sites

Hey ssaket,

Yeah, that is helpful, this way I can check which tiles to dispose, thank you!

But I still don't know how many tiles to load at the beginning. I could just create one tile in the middle of the screen, then add neighbouring tiles in all directions, check if they are in the frustum, if so load the map texture and then check their neighbors but maybe there is a better way to do that; get the width/height directly and calculate how many tiles to load from?

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...