How do I get all the objects that the camera can see?

I tried the Raycaster, but inaccurate results.
How do I get all the objects that the camera can see?
Top view, front view…different objects seen, just seeing, exclude overlap.
Any idea?

Do you mean all the objects that are in the frustum (so rendered)? Then, you can create a onBeforeRender (or onAfterRender) callback on your meshes, as this functions is called only for objects in the frustum.

Thank you for reply!
I do not know, object A is in front of object B, that is, eye(camera) will see object A, can not see object B.
WebGLRenderer will object B be rendered?

Yes. three.js does not support occlusion culling. All objects in the view frustum are rendered.

:sweat_smile:Then how can I only get the object A?

Well, you have to implement something like occlusion culling in your app :innocent:

1 Like

What you can do is rendering your scene with each object having a different color and being flat shaded.

That way, by reading the final framebuffer color one pixel by one pixel, you can know which object this pixel corresponds to (keep a map mapping color to object), and then reconstruct the list of objects that were seen by the camera.

See 2nd method in this tutorial on picking where he uses this rendering method to identify which object is picked.


Thank you for reply!

Thanks for your answer @Popov72, I will try