/// <summary> /// Traces the contour of a navmesh. /// /// [Open online documentation to see images] /// /// This image is just used to illustrate the difference between chains and cycles. That it shows a grid graph is not relevant. /// [Open online documentation to see images] /// /// See: <see cref="GetContours(NavGraph)"/> /// </summary> /// <param name="navmesh">The navmesh-like object to trace. This can be a recast or navmesh graph or it could be a single tile in one such graph.</param> /// <param name="results">Will be called once for each contour with the contour as a parameter as well as a boolean indicating if the contour is a cycle or a chain (see second image).</param> public static void GetContours(INavmesh navmesh, System.Action <List <Int3>, bool> results) { // Assume 3 vertices per node var uses = new bool[3]; var outline = new Dictionary <int, int>(); var vertexPositions = new Dictionary <int, Int3>(); var hasInEdge = new HashSet <int>(); navmesh.GetNodes(_node => { var node = _node as TriangleMeshNode; uses[0] = uses[1] = uses[2] = false; if (node != null) { // Find out which edges are shared with other nodes for (int j = 0; j < node.connections.Length; j++) { var other = node.connections[j].node as TriangleMeshNode; // Not necessarily a TriangleMeshNode if (other != null) { int a = node.SharedEdge(other); if (a != -1) { uses[a] = true; } } } // Loop through all edges on the node for (int j = 0; j < 3; j++) { // The edge is not shared with any other node // I.e it is an exterior edge on the mesh if (!uses[j]) { var i1 = j; var i2 = (j + 1) % node.GetVertexCount(); outline[node.GetVertexIndex(i1)] = node.GetVertexIndex(i2); hasInEdge.Add(node.GetVertexIndex(i2)); vertexPositions[node.GetVertexIndex(i1)] = node.GetVertex(i1); vertexPositions[node.GetVertexIndex(i2)] = node.GetVertex(i2); } } } }); Polygon.TraceContours(outline, hasInEdge, (chain, cycle) => { List <Int3> vertices = ListPool <Int3> .Claim(); for (int i = 0; i < chain.Count; i++) { vertices.Add(vertexPositions[chain[i]]); } results(vertices, cycle); }); }
// Token: 0x0600229B RID: 8859 RVA: 0x00190E64 File Offset: 0x0018F064 public static void GetContours(INavmesh navmesh, Action <List <Int3>, bool> results) { bool[] uses = new bool[3]; Dictionary <int, int> outline = new Dictionary <int, int>(); Dictionary <int, Int3> vertexPositions = new Dictionary <int, Int3>(); HashSet <int> hasInEdge = new HashSet <int>(); navmesh.GetNodes(delegate(GraphNode _node) { TriangleMeshNode triangleMeshNode = _node as TriangleMeshNode; uses[0] = (uses[1] = (uses[2] = false)); if (triangleMeshNode != null) { for (int i = 0; i < triangleMeshNode.connections.Length; i++) { TriangleMeshNode triangleMeshNode2 = triangleMeshNode.connections[i].node as TriangleMeshNode; if (triangleMeshNode2 != null) { int num = triangleMeshNode.SharedEdge(triangleMeshNode2); if (num != -1) { uses[num] = true; } } } for (int j = 0; j < 3; j++) { if (!uses[j]) { int i2 = j; int i3 = (j + 1) % triangleMeshNode.GetVertexCount(); outline[triangleMeshNode.GetVertexIndex(i2)] = triangleMeshNode.GetVertexIndex(i3); hasInEdge.Add(triangleMeshNode.GetVertexIndex(i3)); vertexPositions[triangleMeshNode.GetVertexIndex(i2)] = triangleMeshNode.GetVertex(i2); vertexPositions[triangleMeshNode.GetVertexIndex(i3)] = triangleMeshNode.GetVertex(i3); } } } }); Polygon.TraceContours(outline, hasInEdge, delegate(List <int> chain, bool cycle) { List <Int3> list = ListPool <Int3> .Claim(); for (int i = 0; i < chain.Count; i++) { list.Add(vertexPositions[chain[i]]); } results(list, cycle); }); }