A* Pathfinding Project
3.8.5
The A* Pathfinding Project for Unity 3D
|
Utility class for updating tiles of recast graphs. More...
Utility class for updating tiles of recast graphs.
Primarily used by the TileHandlerHelper for navmesh cutting.
Most operations that this class does are asynchronous. They will be added as work items to the AstarPath class and executed when the pathfinding threads have finished calculating their current paths.
Classes | |
class | Cut |
Internal class describing a single NavmeshCut. More... | |
class | TileType |
A template for a single tile in a recast graph. More... | |
Public Types | |
enum | CutMode { CutAll = 1, CutDual = 2, CutExtra = 4 } |
Public Member Functions | |
TileHandler (RecastGraph graph) | |
void | ClearTile (int x, int z) |
Clear the tile at the specified tile coordinates. | |
void | CreateTileTypesFromGraph () |
void | CutShapeWithTile (int x, int z, Int3[] shape, ref Int3[] verts, ref int[] tris, out int vCount, out int tCount) |
void | EndBatchLoad () |
int | GetActiveRotation (Int2 p) |
TileType | GetTileType (int index) |
int | GetTileTypeCount () |
void | LoadTile (TileType tile, int x, int z, int rotation, int yoffset) |
Load a tile at tile coordinate x, z. | |
void | OnRecalculatedTiles (RecastGraph.NavmeshTile[] recalculatedTiles) |
Call to update the specified tiles with new information based on the recast graph. | |
TileType | RegisterTileType (Mesh source, Int3 centerOffset, int width=1, int depth=1) |
Register that a tile can be loaded from source. | |
void | ReloadInBounds (Bounds b) |
Reloads all tiles intersecting with the specified bounds. | |
void | ReloadTile (int x, int z) |
Reload tile at tile coordinate. | |
bool | StartBatchLoad () |
Start batch loading. | |
Static Protected Member Functions | |
static T[] | ShrinkArray< T > (T[] arr, int newLength) |
Returns a new array with at most length newLength. | |
Properties | |
RecastGraph | graph [get] |
The underlaying graph which this object handles. | |
bool | isValid [get] |
True if the tile handler still has the same number of tiles and tile layout as the graph. | |
Private Member Functions | |
int | ClipAgainstRectangle (Int3[] clipIn, Int3[] clipOut, Int2 size) |
Clips the input polygon against a rectangle with one corner at the origin and one at size in XZ space. | |
void | CompressMesh (List< Int3 > vertices, List< int > triangles, ref Int3[] outVertices, ref int[] outTriangles, out int outVertexCount, out int outTriangleCount) |
Compress the mesh by removing duplicate vertices. | |
void | CopyMesh (Int3[] vertices, int[] triangles, List< Int3 > outVertices, List< int > outTriangles) |
Copy mesh from (vertices, triangles) to (outVertices, outTriangles) | |
void | CutAll (List< IntPoint > poly, List< int > intersectingCutIndices, List< Cut > cuts, Pathfinding.ClipperLib.PolyTree result) |
void | CutDual (List< IntPoint > poly, List< int > tmpIntersectingCuts, List< Cut > cuts, bool hasDual, List< List< IntPoint > > intermediateResult, Pathfinding.ClipperLib.PolyTree result) |
void | CutExtra (List< IntPoint > poly, List< IntPoint > extraClipShape, Pathfinding.ClipperLib.PolyTree result) |
void | CutPoly (Int3[] verts, int[] tris, ref Int3[] outVertsArr, ref int[] outTrisArr, out int outVCount, out int outTCount, Int3[] extraShape, Int3 cuttingOffset, Bounds realBounds, CutMode mode=CutMode.CutAll|CutMode.CutDual, int perturbate=-1) |
Cuts a piece of navmesh using navmesh cuts. | |
void | DelaunayRefinement (Int3[] verts, int[] tris, ref int vCount, ref int tCount, bool delaunay, bool colinear, Int3 worldOffset) |
Refine a mesh using delaunay refinement. | |
Int3 | IntPoint2Int3 (IntPoint p) |
Converts between point types. | |
Vector3 | Point2D2V3 (Poly2Tri.TriangulationPoint p) |
Converts between point types. | |
void | UpdateTileType (RecastGraph.NavmeshTile tile) |
Static Private Member Functions | |
static void | PoolPolygon (Poly2Tri.Polygon polygon, Stack< Poly2Tri.Polygon > pool) |
static List< Cut > | PrepareNavmeshCutsForCutting (List< NavmeshCut > navmeshCuts, Int3 cuttingOffset, IntRect bounds, int perturbate, bool anyNavmeshAdds) |
Generates a list of cuts from the navmesh cut components. | |
static int | SampleYCoordinateInTriangle (Int3 p1, Int3 p2, Int3 p3, Int3 p) |
Sample Y coordinate of the triangle (p1, p2, p3) at the point p in XZ space. | |
Private Attributes | |
readonly RecastGraph | _graph |
Graph which is handled by this instance. | |
readonly int[] | activeTileOffsets |
Offsets along the Y axis of the active tiles. | |
readonly int[] | activeTileRotations |
Rotations of the active tiles. | |
readonly TileType[] | activeTileTypes |
Which tile type is active on each tile index. | |
readonly Dictionary< Int2, int > | cached_Int2_int_dict = new Dictionary<Int2, int>() |
Cached dictionary to avoid excessive allocations. | |
readonly Dictionary< Int3, int > | cached_Int3_int_dict = new Dictionary<Int3, int>() |
Cached dictionary to avoid excessive allocations. | |
int[] | cached_int_array = new int[32] |
Cached int array to avoid excessive allocations. | |
readonly Clipper | clipper = new Clipper() |
Handles polygon clipping operations. | |
bool | isBatching |
True while batching tile updates. | |
readonly bool[] | reloadedInBatch |
A flag for each tile that is set to true if it has been reloaded while batching is in progress. | |
readonly Pathfinding.Voxels.VoxelPolygonClipper | simpleClipper |
Utility for clipping polygons to rectangles. | |
readonly int | tileXCount |
Number of tiles along the x axis. | |
readonly int | tileZCount |
Number of tiles along the z axis. | |
enum CutMode |
TileHandler | ( | RecastGraph | graph | ) |
void ClearTile | ( | int | x, |
int | z | ||
) |
Clear the tile at the specified tile coordinates.
Clips the input polygon against a rectangle with one corner at the origin and one at size in XZ space.
clipIn | Input vertices |
clipOut | Output vertices. This buffer must be large enough to contain all output vertices. |
size | The clipping rectangle has one corner at the origin and one at this position in XZ space. |
|
private |
Compress the mesh by removing duplicate vertices.
vertices | Vertices of the input mesh |
triangles | Triangles of the input mesh |
outVertices | Vertices of the output mesh. If non-null, this buffer will be reused instead of allocating a new one if it is large enough. The indices up to (but not including) outVertexCount are the final vertices. |
outTriangles | Triangles of the output mesh. If non-null, this buffer will be reused instead of allocating a new one if it is large enough. The indices up to (but not including) outVertexCount are the final triangles. |
outVertexCount | The number of vertices in the output mesh. |
outTriangleCount | The number of used indices in the outTriangles array. This will be the number of triangles multiplied by 3. |
|
private |
Copy mesh from (vertices, triangles) to (outVertices, outTriangles)
void CreateTileTypesFromGraph | ( | ) |
|
private |
|
private |
|
private |
|
private |
Cuts a piece of navmesh using navmesh cuts.
void CutShapeWithTile | ( | int | x, |
int | z, | ||
Int3[] | shape, | ||
ref Int3[] | verts, | ||
ref int[] | tris, | ||
out int | vCount, | ||
out int | tCount | ||
) |
|
private |
Refine a mesh using delaunay refinement.
Loops through all pairs of neighbouring triangles and check if it would be better to flip the diagonal joining them using the delaunay criteria.
Does not require triangles to be clockwise, triangles will be checked for if they are clockwise and made clockwise if not. The resulting mesh will have all triangles clockwise.
void EndBatchLoad | ( | ) |
int GetActiveRotation | ( | Int2 | p | ) |
TileType GetTileType | ( | int | index | ) |
int GetTileTypeCount | ( | ) |
|
private |
Converts between point types.
Internal method used for debugging
void LoadTile | ( | TileType | tile, |
int | x, | ||
int | z, | ||
int | rotation, | ||
int | yoffset | ||
) |
Load a tile at tile coordinate x, z.
tile | Tile type to load |
x | Tile x coordinate (first tile is at (0,0), second at (1,0) etc.. ). |
z | Tile z coordinate. |
rotation | Rotate tile by 90 degrees * value. |
yoffset | Offset Y coordinates by this amount. In Int3 space, so if you have a world space offset, multiply by Int3.Precision and round to the nearest integer before calling this function. |
void OnRecalculatedTiles | ( | RecastGraph.NavmeshTile[] | recalculatedTiles | ) |
Call to update the specified tiles with new information based on the recast graph.
This is usually called right after a recast graph has recalculated some tiles and thus some calculations need to be done to take navmesh cutting into account as well.
Will reload all tiles in the list.
|
private |
Converts between point types.
Internal method used for debugging
|
staticprivate |
|
staticprivate |
Generates a list of cuts from the navmesh cut components.
Each cut has a single contour (NavmeshCut components may contain multiple).
Register that a tile can be loaded from source.
centerOffset | Assumes that the mesh has its pivot point at the center of the tile. If it has not, you can supply a non-zero centerOffset to offset all vertices. |
width | width of the tile. In base tiles, not world units. |
depth | depth of the tile. In base tiles, not world units. |
source | Source mesh, must be readable. |
void ReloadInBounds | ( | Bounds | b | ) |
Reloads all tiles intersecting with the specified bounds.
void ReloadTile | ( | int | x, |
int | z | ||
) |
Reload tile at tile coordinate.
The last tile loaded at that position will be reloaded (e.g to account for moved NavmeshCut components)
Sample Y coordinate of the triangle (p1, p2, p3) at the point p in XZ space.
The y coordinate of #p is ignored.
|
staticprotected |
Returns a new array with at most length newLength.
The array will contain a copy of all elements of arr up to but excluding the index newLength.
bool StartBatchLoad | ( | ) |
Start batch loading.
|
private |
|
private |
Graph which is handled by this instance.
|
private |
Offsets along the Y axis of the active tiles.
|
private |
Rotations of the active tiles.
|
private |
Which tile type is active on each tile index.
This array will be tileXCount*tileZCount elements long.
Cached dictionary to avoid excessive allocations.
Cached dictionary to avoid excessive allocations.
|
private |
Cached int array to avoid excessive allocations.
|
private |
Handles polygon clipping operations.
|
private |
True while batching tile updates.
Batching tile updates has a positive effect on performance
|
private |
A flag for each tile that is set to true if it has been reloaded while batching is in progress.
|
private |
Utility for clipping polygons to rectangles.
Implemented as a struct and not a bunch of static methods because it needs some buffer arrays that are best cached to avoid excessive allocations
|
private |
Number of tiles along the x axis.
|
private |
Number of tiles along the z axis.
|
get |
The underlaying graph which this object handles.
|
get |
True if the tile handler still has the same number of tiles and tile layout as the graph.
If the graph is rescanned the tile handler will get out of sync and needs to be recreated.