Info on a mesh (occlusion, distance, orientation, visibility...)

Hi,

Is there a way, without using additional resources (meaning no ray, no computation) , the following info on a mesh:

  • is it in the frustum?
  • is it occluded by another mesh?
  • is it facing towards the camera?
  • what is its distance to the active camera?
    I know of isInFrustum(), getdistancetocamera(), but I dont know if these cost ressources or just read properties that are computed by the rendering pipeline. As for the rest I cannot find anything.

I could really use a little help!

Thanks!

You can use:

scene.isActiveMesh(mesh);

It is looking for the mesh in the current active mesh list (so a simple indexOf). However, you should do this only when the current active mesh list has been built for the current frame. If you do it too soon, you will get the info for the previous frame.

The scene.onBeforeRenderTargetsRenderObservable observable is the first one to be fired after the active mesh list have been built. Other possible observables are:

  • onAfterRenderTargetsRenderObservable
  • onBeforeDrawPhaseObservable
  • onAfterDrawPhaseObservable
  • onAfterCameraRenderObservable
  • onAfterRenderObservable

You must use occlusion queries for that, this information is not readily available.

I don’t really know what mean for a mesh to be facing the camera? How would you check that?

The value you can get from TransformNode.getDistanceToCamera is not stored anywhere for a fast retrieve, but it is only doing a subtract and some muls / a sqrt so it should not be a problem to call it whenever you need it.

2 Likes

Merci @Evgeni_Popov !

Is it facing towards the camera?

I don’t really know what mean for a mesh to be facing the camera? How would you check that?

I was thinking that, since when backface culling is true, the faces facing away from the camera are not rendered, the info on whether the face is facing away or towards the camera would be available. Is it? If not, I guess I have to check the normals.

var norm = mesh.getFacetNormal(5); // returns the world normal of the mesh 5th facet

1 Like