简体   繁体   中英

Calculate whether meshCollider needs to be Convex or Concave in Unity C#?

In Unity is there a way during runtime, when dealing with unknown user-generated shapes for which we now want to create a meshCollider, to calculate whether the mesh should set to be Convex or not, ie whether the meshFilter has inward curves? (It's easy enough to set this property manually by looking at it, but here I'm dealing with unknown-beforehand shapes.) Thanks!

For each triangle in the mesh, you need to calculate its face normal. Then for each face normal, check the sign of the dot product with each vertex to see if its behind the triangle. If all vertices are behind all triangles, it is convex.

Personally, I would just mark everything concave and move on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM