How can I find which mesh the camera can see?

Hi,
2qltZ9EFYj
Like this, top view, can see 10 mesh,
front view only can see 4 mesh
| mesh | mesh |
| mesh | mesh |
in fact total 5 * 2 * 2, 20 mesh.
How to get objects that can be seen in the view?

Hello and welcome!

You have a few options:

2 Likes

Thanks for your reply!
I try ray, line-by-line scan,

let ray = new BABYLON.Ray(new BABYLON.Vector3(-1.cl, i, j), new BABYLON.Vector3(50, i, j));

but result is inaccurate, and the occluded object will be obtained.

I did this once. If you need an absolutely correct list, you can render the scene with the object id as its color, and then process the generated texture to get the list of ids present there. You can even set filters such as minimum of pixels before considering an object actually visible.

You can do that in a separate pass like explained here How to use RenderTargetTexture and run multiple passes - Babylon.js Documentation and we’ve been discussing here How to Override Materials.

There might be much better ideas depending on what you actually want to achieve, so perhaps it would be wiser to explain the original problem you’re trying to solve.

1 Like

Thanks for your reply.
Suppose there is a container, shape is a cube with six faces.There are some cubes inside the container.
I will switch camera mode is ORTHOGRAPHIC_CAMERA and set camera position, observe the six sides of the container.
Top view, bottom view, front view, rear view, left view, right view.


Each view can only see unoccluded cubes, consider only the cubes inside the container.
Want to get the cube that each view can see, this is original problem.

Okay. Using the ids as the color of the mesh or of the face, depending on what your want to detect, will solve it. Remember to use flat shading.