How to select the front triangles of a stl model o

2019-04-14 09:09发布

问题:

There is a stl model(triangular mesh). I want to use a adjustable, rectangular shape to make selections. Like below picture.

But I don't want the triangles on the other side are selected. That's to say only the visible triangles in the rectangular can be selected.

AFAIK, there is a method to do this. First render each triangle with a specific and unique color. Then, retrieve the color of the pixels in the select rectangular, and convert those colors back to the original identifier. The triangle own the id is selected. I think this method is workable but inefficient.

So is there any other better method to do this selection? More elegant and efficient one?

回答1:

This process is called 'picking' and you will have better luck if you search for that. Basically the selected rectangle creates an intersection volume with the view frustum. Primitives outside that intersection volume can be trivially discarded. Primitives inside the volume need to be tested somehow to see which ones are "visible". There are various ways to implement picking, of which color-based picking is just one option.