#Object picking

8 messages · Page 1 of 1 (latest)

copper maple
#

Hi

I want to implement object picking i've read a decent amount into it now but the thing thats puzzling me is that, it picks an individual triangle. How would you go from that triangle to an entire model. So lets say you pick a triangle on a 3D cube, how would you know which cube/object that triangle belongs too?

Sorry if its a simple question I'm new to graphics and i cant get my head around how you would do this in an efficient way.

edgy thistle
#

There are two methods.

#

One is based on rendering a buffer, color for exanple, with unique color per triangle, then reading back the color of pixel(s) you are interested in.

#

Second method is using ray - triangle intersection testing. To do this in performant way, use acceleration structures is necessary. Using libraries like bvh or embree will help there.

#

I have implemented both methods. The ID renderer based method may be slightly less work, but it also needs care to be performant. Specifically, one should use asynchronous buffer transfers when reading the results to CPU. This adds latency, which typically is not problem, but can sometimes be. The other thing that you will need is a method assign colors for triangles that will help you identify object and triangle.

fleet granite
#

As you're talking about object picking on an entire marge mesh (while already, it seems, knowing that you can find a triangle via ray intersection), the optimisation to avoid having to build up a high fidelity ray-intersection process would be to replace interactive objects (anything you may pick) with a "good enough" very broad bounding volume.

#

Ray-sphere intersection tests are cheap so if you can fill you scene with spheres over the things you want to pick then you're laughing. Edge case would be if you get multiple hits at once due to overly generous sphere sizes & you can run some logic around which sphere centre is closer to the camera or which centre is nearest to you ray for how to pick in that case. Just be aware that a user expecting per-pixel object picking accuracy may wonder what is going on (use more spheres with less chance of these edge cases or other volume shapes to reduce this disconnect).