It doesn't look like a duplicate, but see also: How to get an object in 3DG WebGL space with the mouse click
In addition to non-designing and casting the beam (and then performing intersection tests with it as necessary), it is best to look at the “collection”. This will not give accurate 3D coordinates, but it is a useful alternative to non-designing, when you only need to care about which object you clicked on and don’t need pixel accuracy.
Choosing in WebGL means rendering the entire scene (or at least the objects you need) using a specific shader. The shader displays each object with a different unique identifier, which is encoded in the red and green channels using the blue channel as the key (not blue means that the object is not of interest). The scene turns into an offshore framebuffer so that it does not appear to the end user. Then you read back, using gl.readPixels (), the pixel or pixels of interest, and see which object identifier was encoded at that position.
If this helps, see my own implementation of WebGL selection . This implementation selects a rectangular region of pixels; transmission in the 1x1 region results in the selection of one pixel. See also functions on lines 146, 162, and 175.
sinisterchipmunk
source share