# How can I find which mesh the camera can see?

**URL:** <https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196>\
**Category:** Questions\
**Created:** [November 25, 2019, 8:40am UTC](https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196 "2019-11-25T08:40:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jas0n](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jas0n/32/7573_2.png) [@jas0n](https://forum.babylonjs.com/u/jas0n)\
**Post date:** [November 25, 2019, 8:40am UTC](https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196/1 "2019-11-25T08:40:59Z")

</div>

Hi,  
 ![2qltZ9EFYj](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/4/487473cd7afc0ff80817ba414bfb258db0725ebd.png)  
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?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [November 25, 2019, 3:56pm UTC](https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196/2 "2019-11-25T15:56:16Z")

</div>

Hello and welcome!

You have a few options:

- Use occlusion queries: [Occlusion Queries - Babylon.js Documentation](https://doc.babylonjs.com/features/occlusionquery)
- Launching rays: [Picking Collisions - Babylon.js Documentation](https://doc.babylonjs.com/babylon101/picking_collisions)

---

<div class="post-metadata">

**Author:** ![jas0n](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jas0n/32/7573_2.png) [@jas0n](https://forum.babylonjs.com/u/jas0n)\
**Post date:** [November 26, 2019, 7:28am UTC](https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196/3 "2019-11-26T07:28:58Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![brunobg](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brunobg/32/5523_2.png) [@brunobg](https://forum.babylonjs.com/u/brunobg)\
**Post date:** [November 26, 2019, 8:30pm UTC](https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196/4 "2019-11-26T20:30:57Z")

</div>

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](https://doc.babylonjs.com/how_to/how_to_use_rendertargettexture_and_multiple_passes) and we’ve been discussing here [How to Override Materials](https://forum.babylonjs.com/t/how-to-override-materials/6721).

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.

---

<div class="post-metadata">

**Author:** ![jas0n](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jas0n/32/7573_2.png) [@jas0n](https://forum.babylonjs.com/u/jas0n)\
**Post date:** [November 27, 2019, 2:57am UTC](https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196/5 "2019-11-27T02:57:12Z")

</div>

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.

 ![wSPgkO6R6F](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/d/dbd6e2c68223042a86386679f7fc5d04b6a62fa7.png)  
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.

---

<div class="post-metadata">

**Author:** ![brunobg](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brunobg/32/5523_2.png) [@brunobg](https://forum.babylonjs.com/u/brunobg)\
**Post date:** [November 27, 2019, 2:47pm UTC](https://forum.babylonjs.com/t/how-can-i-find-which-mesh-the-camera-can-see/7196/6 "2019-11-27T14:47:05Z")

</div>

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.
