void BuildGraph() { var gb = new SimpleGraphBuilder(); var positions = new List <Vector3>(); for (int i = 0; i < gridSpace.NumCells; i++) { positions.Add(gridSpace.GetBounds(i).center); gb.NewNode(); var neighbours = new List <int>(); foreach (var dir in CompassDirection.PrincipalDirections) { int neighbour; if (gridSpace.TryGetNeighbour(i, dir, out neighbour)) { neighbours.Add(neighbour); } } gb.AddArcs(neighbours.ToArray()); } var graph = gb.Build(); potentialFieldSys.SetGraph(graph, positions.ToArray()); }
/// <summary> /// Builds a <see cref="SimpleGraph"/> of the mesh with one node per vertex and a directed arc for each connecting triangle edge. /// </summary> /// <remarks> /// The mesh must not have co-incident vertices to work properly. Imported meshes usually have duplicate vertices so that UVs and /// normals can be stored. Setting the normals mode to "calculate", with a smoothing angle of 180 degrees, will remove the duplicates. /// </remarks> /// <returns>The graph.</returns> /// <param name="mesh">The mesh to build the graph for.</param> public static SimpleGraph BuildSimpleGraph(this Mesh mesh) { var verts = mesh.vertices; var tris = mesh.triangles; var builder = new SimpleGraphBuilder(); for (int i = 0; i < verts.Length; i++) { builder.NewNode(); var arcs = new HashSet <int>(); for (int j = 0; j < tris.Length; j += 3) { var i0 = tris[j]; var i1 = tris[j + 1]; var i2 = tris[j + 2]; if (i0 == i) { arcs.Add(i1); arcs.Add(i2); } else if (i1 == i) { arcs.Add(i0); arcs.Add(i2); } else if (i2 == i) { arcs.Add(i0); arcs.Add(i1); } } builder.AddArcs(arcs.ToArray()); } return(builder.Build()); }
protected internal virtual Dijkstra <double> GetDijkstra(SimpleGraphBuilder graph, double?startCost, string startNode, string endNode) { return(new Dijkstra <double>(startCost, graph.GetNode(startNode), graph.GetNode(endNode), CommonEvaluators.doubleCostEvaluator("cost"), new DoubleAdder(), double?.compareTo, Direction.BOTH, MyRelTypes.R1)); }