Jump to content

Get visible meshes. Octree?


viktov
 Share

Recommended Posts

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

but 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,

Regards

V.

Link to comment
Share on other sites

  • 2 years later...

@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

Link to comment
Share on other sites

@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 by Gil
I tested the code
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...