- Home /
How to find the portion of a 3D object that is exposed from a specific angle?
I am beginning to make an aerodynamics system for 3d objects. To do this I will need to know what part of the object is exposed and what part is shielded from the airstream (which will come from a certain direction). See the examples in the image.
I can then apply aerodynamics to the exposed area. I'm not really sure how to find this area, however. Whether I end up detecting the area using colliders, mesh triangles, or something else doesn't really matter to me. My best idea so far is sending out a dense wall of parallel raycasts (which represent the wind) towards the object and returning the surfaces hit. Since a surface can be partially obscured I would have to split the object into many small surfaces (requiring a higher density of raycasts) for higher accuracy. It seems inefficient to use raycasts like this every frame. At first, I thought spherecastall would help, but that seems to return everything the sphere touches, even if obscured behind another object. Another idea I've toyed with is using a camera. Maybe an orthographic camera can tell me what surfaces are visible, and therfore exposed?
Answer by MattG54321 · Feb 26, 2019 at 06:54 PM
I think you're on the right track in terms of using many parallel raycasts. However, instead of breaking down the object into many small surfaces, I would instead take advantage of RaycastHit.point, which will give you the point of contact for the raycast. You can then use all the points you get from your raycasts to build a new surface that only has the exposed parts included. There's many ways to make this new surface off of the points you got from the raycast, and which one is best will depend on what you intend to do with it.
Increasing the density of your raycasts (just raycasting more per unit area) will give you a higher resolution approximation. Depending on the meshes you're analyzing, it could be better to do a raycast for each vertex instead of blindly raycasting everywhere.