servusdei Posted November 16, 2018 Share Posted November 16, 2018 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. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted November 16, 2018 Share Posted November 16, 2018 try this: parent.computeWorldMatrix(); https://www.babylonjs-playground.com/#ZJYNY#96 logs. true, false. check the frustum computation servusdei 1 Quote Link to comment Share on other sites More sharing options...
servusdei Posted November 17, 2018 Author Share Posted November 17, 2018 Thanks; What also drived me crazy is that if the camera is created in the assetsManager.onFinish(), the camera.isInFrustum() does not work as expected. so I had to create it before assets are loaded. Quote Link to comment Share on other sites More sharing options...
servusdei Posted November 17, 2018 Author Share Posted November 17, 2018 Hi @brianzinn In this example, camera.isInFrustum(mesh) keeps returning true when it should not : https://www.babylonjs-playground.com/#ZJYNY#97 Moreover, If I swap these lines, it works but the meshe does not render to x = 10; mesh.computeWorldMatrix(); mesh.position.x = 10; Why would that be the case ? Thanks. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 19, 2018 Share Posted November 19, 2018 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: 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 servusdei 1 Quote Link to comment Share on other sites More sharing options...
servusdei Posted November 19, 2018 Author Share Posted November 19, 2018 @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. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 19, 2018 Share Posted November 19, 2018 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(); https://www.babylonjs-playground.com/#ZJYNY#103 or you could do your check AfterRender to ensure that all your required info would have been computed. servusdei 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.