raysect / source

The main source repository for the Raysect project.
http://www.raysect.org
BSD 3-Clause "New" or "Revised" License
88 stars 23 forks source link

Getting id of intersected mesh face #323

Closed Mateasek closed 2 years ago

Mateasek commented 4 years ago

Recently I needed to get the id of the face which was hit by a ray. Is there now any way of getting it? For now I've solved it by adding a class variable to the 'Intersect' class as an optional parameter in the init() function and passed the id in the 'MeshData.calc_intersection' method.

This is probably not the best way how to do it, but such functionality could nicely extend usage of Raysect. At least for me.

mattngc commented 4 years ago

Sounds like this needs UV coordinates to be added to the mesh. Not a small task. Adding it to the Intersection object though isn't really generally appropriate as its unique to a single primitive.

I agree though, this would be useful if such a mechanism was available. Doing it in a way that isn't hacky might take some time.

mattngc commented 4 years ago

Was thinking more about this, I guess the pathway for adding this would be:

  1. Allow each primitive to specify its own UV coodinates.
  2. Add a tuple of UV coordinates to the Intersection object.
  3. Use the intersection UV coordinates to lookup the triangle ID on MeshData.

This would be the most general pathway and allow other usage as well. But there is a lot of work in adding it all.

CnlPepper commented 4 years ago

I'd use a Point2D, not a tuple.

mattngc commented 4 years ago

@CnlPepper and I were talking about this in the office. We think the Intersection object could be modified to take a material object chosen by the primitive. This could include references to the missing coordinate information.

CnlPepper commented 2 years ago

Fixed in release 0.8.0. Meshes return a mesh specific intersection object with triangle ID and barycentric coordinates accessible. UV coords can be added later with wider texturing support.