Given a fully opaque 3D mesh and instrinsic and extrinsic matrices for a camera, I want to determine, for a pixel (x,y), the id of the contributing triangle 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 way to address this problem?
1