/** Creates a list for every tile and adds every mesh that touches a tile to the corresponding list */ public static List <RasterizationMesh>[] PutMeshesIntoTileBuckets(this RecastGraph self, List <RasterizationMesh> meshes) { var result = new List <RasterizationMesh> [self.tiles.Length]; var borderExpansion = new Vector3(1, 0, 1) * self.TileBorderSizeInWorldUnits * 2; for (int i = 0; i < result.Length; i++) { result[i] = ListPool <RasterizationMesh> .Claim(); } for (int i = 0; i < meshes.Count; i++) { var mesh = meshes[i]; var bounds = mesh.bounds; // Expand borderSize voxels on each side bounds.Expand(borderExpansion); var rect = self.GetTouchingTiles(bounds); for (int z = rect.ymin; z <= rect.ymax; z++) { for (int x = rect.xmin; x <= rect.xmax; x++) { result[x + z * self.tileXCount].Add(mesh); } } } return(result); }
/** Requests an update to all tiles which touch the specified bounds */ public void ScheduleUpdate(Bounds bounds) { if (graph == null) { // If no graph has been set, use the first graph available if (AstarPath.active != null) { SetGraph(AstarPath.active.data.recastGraph); } if (graph == null) { Debug.LogError("Received tile update request (from RecastTileUpdate), but no RecastGraph could be found to handle it"); return; } } // Make sure that tiles which do not strictly // contain this bounds object but which still // might need to be updated are actually updated int voxelCharacterRadius = Mathf.CeilToInt(graph.characterRadius / graph.cellSize); int borderSize = voxelCharacterRadius + 3; // Expand borderSize voxels on each side bounds.Expand(new Vector3(borderSize, 0, borderSize) * graph.cellSize * 2); var touching = graph.GetTouchingTiles(bounds); if (touching.Width * touching.Height > 0) { if (!anyDirtyTiles) { earliestDirty = Time.time; anyDirtyTiles = true; } for (int z = touching.ymin; z <= touching.ymax; z++) { for (int x = touching.xmin; x <= touching.xmax; x++) { dirtyTiles[z * graph.tileXCount + x] = true; } } } }