viktov Posted June 17, 2014 Share Posted June 17, 2014 Hi, I wonder what is the best way to get only these meshes which are visible by camera at the moment.I know there is octree implementation in babylon, but Im not sure how to use it.I've seen this https://github.com/BabylonJS/Babylon.js/wiki/Optimizing-performances-with-octreesbut still have problems to make it work. If someone could explain (write a piece of code or pseudo code) how to make it.Lets say I have 5 cubes on my scene and a free camera.I would like to have a function that would return meshes which are visible in a viewport of my camera. Thank you,RegardsV. Quote Link to comment Share on other sites More sharing options...
celian-garcia Posted June 17, 2014 Share Posted June 17, 2014 Hey !There is a BABYLON.Scene function named isActiveMesh(mesh) : It returns true if the mesh in parameter is active (visible from the camera) and false otherwise. I hope it will help you. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 17, 2014 Share Posted June 17, 2014 You also have a list of active meshes: scene.getActiveMeshes which is a smartArray of active (visible) meshes Quote Link to comment Share on other sites More sharing options...
viktov Posted June 17, 2014 Author Share Posted June 17, 2014 Thank you Quote Link to comment Share on other sites More sharing options...
Gil Posted April 12, 2017 Share Posted April 12, 2017 Hello, I came by to that post. The functions are usefull but are not precise enough to know if a mesh is drawed or occuled. At least not with my tests. Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted April 12, 2017 Share Posted April 12, 2017 @Gil You can also build your own array with camera.isInFrustum(mesh) var meshesInFrustum = []; function updateFrustum(){ meshesInFrustum.length = 0; for(var i = 0, length = scene.meshes.length; i < length; i++){ var mesh = scene.meshes[i]; if( mesh && mesh.isVisible && camera.isInFrustum(mesh) ) meshesInFrustum.push(mesh); } } scene.registerBeforeRender(function(){ updateFrustum(); }); http://www.babylonjs-playground.com/#LB6QV9 Quote Link to comment Share on other sites More sharing options...
Gil Posted April 12, 2017 Share Posted April 12, 2017 (edited) @aWeirdo That's a cool solution ! Thanks ! I just tested and that still don't take into account if a mesh is occuling another.http://www.babylonjs-playground.com/#LB6QV9#1 I'm looking for a different way to solve my issue by checking if a mesh is facing the current camera to do what I want. Edited April 13, 2017 by Gil I tested the code 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.