public static RoadGraph BakeRoadGraph(IEnumerable <RoadGraphBuildNode> buildNodes) { var bakedNodes = new List <RoadGraphNode>(); int _edgeIdCounter = 0; foreach (var node in buildNodes) { var bakedNode = new RoadGraphNode(); bakedNode.nodeId = node.nodeId; bakedNode.position = node.position; var edges = new List <RoadGraphEdge>(); for (int i = 0; i < node.connectedNodes.Count; i++) { var connectedNode = node.connectedNodes[i]; var edgeThickness = node.edgeThickness[i]; var edge = new RoadGraphEdge(); edge.edgeId = ++_edgeIdCounter; edge.ownerNodeId = node.nodeId; edge.otherNodeId = connectedNode.nodeId; edge.thickness = edgeThickness; // Find the dot product with the x axis Vector3 direction = (connectedNode.position - node.position).normalized; var dot = Vector3.Dot(new Vector3(1, 0, 0), direction); float angle = Mathf.Acos(dot); if (direction.z < 0) { angle = 2 * Mathf.PI - angle; } edge.angleToXAxis = angle; edges.Add(edge); } bakedNode.adjacentEdges = edges.ToArray(); System.Array.Sort(bakedNode.adjacentEdges, SortEdgesByAngle); bakedNodes.Add(bakedNode); } var graph = new RoadGraph(); graph.nodes = bakedNodes.ToArray(); return(graph); }
public RoadGraphBuildNode(RoadGraphNode graphNode) { nodeId = graphNode.nodeId; position = graphNode.position; }