简体   繁体   English

如何在Unity 3d中获取NavMesh多边形

[英]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? 团结甚至允许这种员工吗?还是您需要再次从github下载内容或在资产商店中购买商品?

I find this post https://forum.unity.com/threads/accessing-navmesh-vertices.130883/ but it help find only vertices, not polygons or something.. 我发现这篇文章https://forum.unity.com/threads/accessing-navmesh-vertices.130883/,但它仅有助于查找顶点,而不能查找多边形或其他内容。

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 来源: https : //docs.unity3d.com/ScriptReference/AI.NavMeshTriangulation-indices.html

Triangle indices for the navmesh triangulation. 导航网格三角剖分的三角形索引。 Contains 3 integers for each triangle. 每个三角形包含3个整数。 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 https://docs.unity3d.com/540/Documentation/ScriptReference/NavMesh.SamplePosition.html

From this source: "Finds the closest point on NavMesh within specified range." 从此来源:“在指定范围内找到NavMesh上的最近点。”

https://docs.unity3d.com/530/Documentation/ScriptReference/NavMesh.Raycast.html 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. " “在NavMesh上的两个点之间跟踪一条线。bool如果射线在到达目标位置之前被终止,则为True。否则返回false。”

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

"Locate the closest NavMesh edge from a point on the NavMesh." “从NavMesh上的点定位最近的NavMesh边缘。”


What exactly are you needing the navmesh data for? 您究竟需要什么导航数据?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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