I have a 3D mesh (fully opaque) and camera instrinsic and extrinsic matrices, and I want to determine, for a pixel (x,y), the id of the triangle we see at that pixel on the rendered image. The purpose is to design a mesh editor so that, when I drag the mouse through the rendered image, I can remove the visible triangles that intersect with the dragging path, which requires us to know the frontmost triangles. There is a simple way: encode the id of each triangle into its RGB color and decode the color of the rendered pixel, but this can only handle up to 256^3 triangles. Currently, my viewer is written in Python using open3d
library, so I prefer a Python solution (it’s still OK, though, when C++ is required and I must wrap the code to build a Python module). Is there an efficient and elegant solution?