source icon indicating copy to clipboard operation
source copied to clipboard

Getting id of intersected mesh face

Open Mateasek opened this issue 6 years ago • 4 comments

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.

Mateasek avatar Nov 14 '19 17:11 Mateasek

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 avatar Nov 14 '19 18:11 mattngc

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.

mattngc avatar Nov 25 '19 11:11 mattngc

I'd use a Point2D, not a tuple.

CnlPepper avatar Nov 26 '19 22:11 CnlPepper

@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.

mattngc avatar Nov 29 '19 16:11 mattngc

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.

CnlPepper avatar Sep 15 '22 00:09 CnlPepper