3

I want to understand the algorithmic approach to getting the normal of a raycast hit in Unity. I understand the math/theory behind raycasting against a simple collider, but once that is accomplished, how does the engine actually traverse the mesh and get the specific face that was hit?

Assuming there's some underlying spatial data structure (octree/k-d tree) at work here, what component (collider or mesh filter maybe?) stores it and how could I directly access this structure?

Lastly, is raycasthit.normal lazily evaluated or is it automatically computed with each raycast hit? Obviously this is important because I don't want some complex algorithm needlessly determining the specific normal of a cast on a complicated object if I'm only worried about the presence of a hit or not...

I cant seem to find long, detailed documentation on this.

Will Snyder
  • 51
  • 1
  • 3
  • 4
    Unity uses PhysX 3.4 (4.1 soon™) under the scene, you should be able to dig it from its documentation. Edit: https://docs.nvidia.com/gameworks/content/gameworkslibrary/physx/guide/Manual/SceneQueries.html PS. PhysX have been opensourced, you can get access to its code via NVidia Developer site. – R2RT Aug 26 '19 at 14:08
  • After reading through some of the source code on git I have a better grasp of the mesh processing side, but still I'd love to know if Unity automatically calls a full raycast against a triangle mesh for every hit against a primitive/convex collider... Also I'm no C++ guy so some of the code @ https://github.com/NVIDIAGameWorks/PhysX/blob/4.1/physx/source/geomutils/src/GuAABBTreeQuery.h is hard to comprehend, if someone could provide a concise summary that would be swell. – Will Snyder Aug 26 '19 at 17:28

0 Answers0