views:

55

answers:

1

I have a 3d polygon mesh and a corresponding 2d polygon mesh (actually from a uv map) which I'm using to map the geometry onto a 2d plane. Given a point on the plane, how can I efficiently find the polygon on which it's resting in order to map that 2d point back into 3d?

The best approach I can think of is to store the polygons in a 2d interval tree, and use that to get candidate polygons. Is there a simpler approach?

Edit: To clarify, this is not for a shader. I'm actually taking a 2D physical simulation and rendering it wrapped around a 3d mesh. For drawing each object, I need to figure out what point in 3d corresponds to its real 2d position.

A: 
brainjam
Thanks, I thought of doing something like this to update to new positions each frame, which would work well given that things don't generally move very far in a frame. Unfortunately, my meshes can be concave or have holes, so I might end up having to use some sort of space partitioning tree, I'm thinking quadtrees instead of 2d interval trees for simplicity.
Henk
@Henk, when you say your meshes can be concave of have holes, do you mean the polygons?
brainjam