[Closed] Returning ray intersection…
Thanks, Martijn! The speed gain seems almost negligible, but I do find the code a lot cleaner. It’s pretty fast, though, clocking in at around .04 seconds for a 20K polygon object on my modest system. That’s compared to about .015 seconds on a ~8K object, so there appears to be an almost linear increase in execution time as poly count increases. Haven’t done enough testing to make any real conclusion, though.
<allonym>
Hey allonym, nice function but that is not entirely true. 3 verts can share 2 faces in very special cases. It doesn’t usually happen though. Check out the image I’ve attached for such a case.
I wrote an intersection function for poly objects before but it only calculates against triangles and works for a triangulated object very quickly. I didn’t find a good way to get how a poly face is triangulated though so I got stuck on that part. I tried to quickly triangulate the small part that got hit by connecting the verts and afterwards remove the edges but that’s a bit dirty. I might look into that a bit more later but I too wish Autodesk would add such support.
CML
Rivendale,
You’re showing a case in which 3 verts share more than one polygon, which is probably quite common. However, the mesh is triangulated, and as you can see from the revised image I’ve attached, the verts of any one of those triangles can lie in only one polygon.
<allonym>
allonym – ah I looked closer at your code now and you are correct, didn’t fully understand what you were doing but I see now that it should work. Good stuff.
edit: on second(or third) thought. I take that back. In my example you would indeed get 2 faces in the final array since the poly faces are not triangulated.
CML
Cool optimization. I will check it out when I’m home. Mmm, I hope it works fast enough on 300k objects. Doesn’t have to be faster than say 0.5-1sec though.
/Andreas
Rivendale,
Your second (third) though is correct! I misinterpreted the image you attached, and now understand that the verts in question would result in an ambiguity – a rare case as you have suggested, but pointing to an obvious flaw in my function’s logic. I have a potential fix which shouldn’t add too much overhead; I will tinker with it when I get home tonight.
Thank you for continuing to think it through;)
<allonym>