简体   繁体   中英

How to get NavMesh polygons in Unity 3d

Question is simple, but i can't find answer on the land of internet. How to get all polys of navmesh, how to find closest ones, how to find centers of these polys, how to find polys connected to specific one, and so on?

Does unity even allow this kind of staff or you need again to download something from github or buy some on asset store?

I find this post https://forum.unity.com/threads/accessing-navmesh-vertices.130883/ but it help find only vertices, not polygons or something..

So, does anyone know anything about this?

The solution :

    var navMesh = NavMesh.CalculateTriangulation();
    Vector3[] vertices = navMesh.vertices;
    int[] polygons = navMesh.indices;

Source: https://docs.unity3d.com/ScriptReference/AI.NavMeshTriangulation-indices.html

Triangle indices for the navmesh triangulation. Contains 3 integers for each triangle. These integers refer to the vertices array.

Should be the points in each polygon if I'm not mistaken.


Other useful methods :

https://docs.unity3d.com/540/Documentation/ScriptReference/NavMesh.SamplePosition.html

From this source: "Finds the closest point on NavMesh within specified range."

https://docs.unity3d.com/530/Documentation/ScriptReference/NavMesh.Raycast.html

"Trace a line between two points on the NavMesh. bool True if the ray is terminated before reaching target position. Otherwise returns false. "

https://docs.unity3d.com/530/Documentation/ScriptReference/NavMesh.FindClosestEdge.html

"Locate the closest NavMesh edge from a point on the NavMesh."


What exactly are you needing the navmesh data for?

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