Jump to content

issue with camera.isInFrustum()


servusdei
 Share

Recommended Posts

Hello,

1-In the example below, I load a small mesh, then I clone it and set the clone's parent to an AbstractMesh. then I position the parent to be outside of the camera frustum.

My issue is why does camera.isInFrustum(parent) returns true even if the parent is outside the camera's viewport ?

https://www.babylonjs-playground.com/#ZJYNY#95

2- Another issue I noticed,  sometimes camera.isInFrustum(mesh) does not return true, after the mesh (which is in the camera frustum) has loaded.

 

Link to comment
Share on other sites

In this example, camera.isInFrustum(mesh) keeps returning true when it should not 

This is because the new value (10) is not taking in account here for the isInFrustum compute. Indeed the computeWorldMatrix will cache the wrong value for the function call but it is recomputed during the rendering.

Moreover, If I swap these lines, it works but the meshe does not render to x = 10;

Here the opposite happens, the computeWorldMatrix will fill the cache with the correct value but then during rendering as the rendered mesh is a child of the one you are computing the value on:

image.png.08bfd03a99400bcb5f4f70595f18b867.png

It does not compute its matrix anymore. What you want is force the compute of the entire hierarchy:

https://www.babylonjs-playground.com/#ZJYNY#100

 

Link to comment
Share on other sites

@Sebavan

Thanks a lot for your explanation. Even when you have forced compute the entire hierarchy I still see the mesh. (should be at x=10).

I want to check one final time with a simple sphere,  and camera.isInFrustum(sphere) unexpectedly returns true.

https://www.babylonjs-playground.com/#ZJYNY#102

What do I do in this case ? the sphere does not have any parent.

 

Link to comment
Share on other sites

This is because the camera has just been created  but none of its information has been computed at the time of your call to isInFrustrum.

you can either force the camera to update at least once with :

camera.getViewMatrix();

camera.getProjectionMatrix();
 
 
or you could do your check AfterRender to ensure that all your required info would have been computed.
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...