A* Pathfinding Project  4.1.19
The A* Pathfinding Project for Unity 3D
TileHandler Class Reference

Utility class for updating tiles of navmesh/recast graphs. More...

Detailed Description

Utility class for updating tiles of navmesh/recast graphs.

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.

See also
Navmesh Cutting
Pathfinding.NavmeshUpdates

Classes

class  Cut
 Internal class describing a single NavmeshCut. More...
 
struct  CuttingResult
 Internal class representing a mesh which is the result of the CutPoly method. More...
 
class  TileType
 A template for a single tile in a navmesh/recast graph. More...
 

Public Types

enum  CutMode { CutAll = 1, CutDual = 2, CutExtra = 4 }
 

Public Member Functions

 TileHandler (NavmeshBase graph)
 
void ClearTile (int x, int z)
 Clear the tile at the specified tile coordinates. More...
 
void CreateTileTypesFromGraph ()
 
void EndBatchLoad ()
 
int GetActiveRotation (Int2 p)
 Rotation of the specified tile relative to the original rotation of the tile type. More...
 
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. More...
 
void OnRecalculatedTiles (NavmeshTile[] recalculatedTiles)
 Call to update the specified tiles with new information based on the navmesh/recast graph. More...
 
TileType RegisterTileType (Mesh source, Int3 centerOffset, int width=1, int depth=1)
 Register that a tile can be loaded from source. More...
 
void ReloadInBounds (Bounds bounds)
 Reloads all tiles intersecting with the specified bounds. More...
 
void ReloadInBounds (IntRect tiles)
 Reloads all tiles specified by the rectangle. More...
 
void ReloadTile (int x, int z)
 Reload tile at tile coordinate. More...
 
void StartBatchLoad ()
 Start batch loading. More...
 

Public Attributes

readonly GridLookup< NavmeshClippercuts
 NavmeshCut and NavmeshAdd components registered to this tile handler. More...
 
readonly NavmeshBase graph
 The underlaying graph which is handled by this instance. More...
 

Properties

bool isBatching [get]
 True while batching tile updates. More...
 
bool isValid [get]
 True if the tile handler still has the same number of tiles and tile layout as the graph. More...
 

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. More...
 
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)
 
CuttingResult CutPoly (Int3[] verts, int[] tris, Int3[] extraShape, GraphTransform graphTransform, IntRect tiles, CutMode mode=CutMode.CutAll|CutMode.CutDual, int perturbate=-1)
 Cuts a piece of navmesh using navmesh cuts. More...
 
void DelaunayRefinement (Int3[] verts, int[] tris, ref int tCount, bool delaunay, bool colinear)
 Refine a mesh using delaunay refinement. More...
 
void UpdateTileType (NavmeshTile tile)
 

Static Private Member Functions

static void CopyMesh (Int3[] vertices, int[] triangles, List< Int3 > outVertices, List< int > outTriangles)
 Copy mesh from (vertices, triangles) to (outVertices, outTriangles) More...
 
static void PoolPolygon (Poly2Tri.Polygon polygon, Stack< Poly2Tri.Polygon > pool)
 
static List< CutPrepareNavmeshCutsForCutting (List< NavmeshCut > navmeshCuts, GraphTransform transform, IntRect cutSpaceBounds, int perturbate, bool anyNavmeshAdds)
 Generates a list of cuts from the navmesh cut components. More...
 

Private Attributes

readonly int [] activeTileOffsets
 Offsets along the Y axis of the active tiles. More...
 
readonly int [] activeTileRotations
 Rotations of the active tiles. More...
 
readonly TileType [] activeTileTypes
 Which tile type is active on each tile index. More...
 
int batchDepth
 Positive while batching tile updates. More...
 
readonly Dictionary< Int2, int > cached_Int2_int_dict = new Dictionary<Int2, int>()
 Cached dictionary to avoid excessive allocations. More...
 
readonly Clipper clipper = new Clipper()
 Handles polygon clipping operations. More...
 
readonly bool [] reloadedInBatch
 A flag for each tile that is set to true if it has been reloaded while batching is in progress. More...
 
readonly Pathfinding.Voxels.Int3PolygonClipper simpleClipper
 Utility for clipping polygons to rectangles. More...
 
readonly int tileXCount
 Number of tiles along the x axis. More...
 
readonly int tileZCount
 Number of tiles along the z axis. More...
 

Member Enumeration Documentation

◆ CutMode

enum CutMode
strong
Enumerator
CutAll 

Cut holes in the navmesh.

CutDual 

Cut the navmesh but do not remove the interior of the cuts.

CutExtra 

Also cut using the extra shape that was provided.

Constructor & Destructor Documentation

◆ TileHandler()

Member Function Documentation

◆ ClearTile()

void ClearTile ( int  x,
int  z 
)

Clear the tile at the specified tile coordinates.

◆ ClipAgainstRectangle()

int ClipAgainstRectangle ( Int3 []  clipIn,
Int3 []  clipOut,
Int2  size 
)
private

Clips the input polygon against a rectangle with one corner at the origin and one at size in XZ space.

Parameters
clipInInput vertices
clipOutOutput vertices. This buffer must be large enough to contain all output vertices.
sizeThe clipping rectangle has one corner at the origin and one at this position in XZ space.
Returns
Number of output vertices

◆ CopyMesh()

static void CopyMesh ( Int3 []  vertices,
int []  triangles,
List< Int3 outVertices,
List< int >  outTriangles 
)
staticprivate

Copy mesh from (vertices, triangles) to (outVertices, outTriangles)

◆ CreateTileTypesFromGraph()

void CreateTileTypesFromGraph ( )

◆ CutAll()

void CutAll ( List< IntPoint >  poly,
List< int >  intersectingCutIndices,
List< Cut cuts,
Pathfinding.ClipperLib.PolyTree  result 
)
private

◆ CutDual()

void CutDual ( List< IntPoint >  poly,
List< int >  tmpIntersectingCuts,
List< Cut cuts,
bool  hasDual,
List< List< IntPoint > >  intermediateResult,
Pathfinding.ClipperLib.PolyTree  result 
)
private

◆ CutExtra()

void CutExtra ( List< IntPoint >  poly,
List< IntPoint >  extraClipShape,
Pathfinding.ClipperLib.PolyTree  result 
)
private

◆ CutPoly()

CuttingResult CutPoly ( Int3 []  verts,
int []  tris,
Int3 []  extraShape,
GraphTransform  graphTransform,
IntRect  tiles,
CutMode  mode = CutMode.CutAll | CutMode.CutDual,
int  perturbate = -1 
)
private

Cuts a piece of navmesh using navmesh cuts.

Note
I am sorry for the really messy code in this method. It really needs to be refactored.
Parameters
vertsVertices that are going to be cut. Should be in graph space.
trisTriangles describing a mesh using the vertices.
extraShapeIf supplied the resulting mesh will be the intersection of the input mesh and this mesh.
graphTransformTransform mapping graph space to world space.
See also
NavmeshBase.transform
Parameters
tilesTiles in the recast graph which the mesh covers.
mode
See also
CutMode
Parameters
perturbateMove navmesh cuts around randomly a bit, the larger the value the more they are moved around. Used to prevent edge cases that can cause the clipping to fail.

◆ DelaunayRefinement()

void DelaunayRefinement ( Int3 []  verts,
int []  tris,
ref int  tCount,
bool  delaunay,
bool  colinear 
)
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.

See also
https://en.wikipedia.org/wiki/Delaunay_triangulation

◆ EndBatchLoad()

void EndBatchLoad ( )

◆ GetActiveRotation()

int GetActiveRotation ( Int2  p)

Rotation of the specified tile relative to the original rotation of the tile type.

A result N means that the tile has been rotated N*90 degrees.

◆ GetTileType()

TileType GetTileType ( int  index)

◆ GetTileTypeCount()

int GetTileTypeCount ( )

◆ LoadTile()

void LoadTile ( TileType  tile,
int  x,
int  z,
int  rotation,
int  yoffset 
)

Load a tile at tile coordinate x, z.

Parameters
tileTile type to load
xTile x coordinate (first tile is at (0,0), second at (1,0) etc.. ).
zTile z coordinate.
rotationRotate tile by 90 degrees * value.
yoffsetOffset 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.

◆ OnRecalculatedTiles()

void OnRecalculatedTiles ( NavmeshTile []  recalculatedTiles)

Call to update the specified tiles with new information based on the navmesh/recast graph.

This is usually called right after a navmesh/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.

◆ PoolPolygon()

static void PoolPolygon ( Poly2Tri.Polygon  polygon,
Stack< Poly2Tri.Polygon >  pool 
)
staticprivate

◆ PrepareNavmeshCutsForCutting()

static List<Cut> PrepareNavmeshCutsForCutting ( List< NavmeshCut navmeshCuts,
GraphTransform  transform,
IntRect  cutSpaceBounds,
int  perturbate,
bool  anyNavmeshAdds 
)
staticprivate

Generates a list of cuts from the navmesh cut components.

Each cut has a single contour (NavmeshCut components may contain multiple).

transform should transform a point from cut space to world space.

◆ RegisterTileType()

TileType RegisterTileType ( Mesh  source,
Int3  centerOffset,
int  width = 1,
int  depth = 1 
)

Register that a tile can be loaded from source.

Parameters
centerOffsetAssumes 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.
widthwidth of the tile. In base tiles, not world units.
depthdepth of the tile. In base tiles, not world units.
sourceSource mesh, must be readable.
Returns
Identifier for loading that tile type

◆ ReloadInBounds() [1/2]

void ReloadInBounds ( Bounds  bounds)

Reloads all tiles intersecting with the specified bounds.

◆ ReloadInBounds() [2/2]

void ReloadInBounds ( IntRect  tiles)

Reloads all tiles specified by the rectangle.

◆ ReloadTile()

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)

◆ StartBatchLoad()

void StartBatchLoad ( )

Start batch loading.

Every call to this method must be matched by exactly one call to EndBatchLoad.

◆ UpdateTileType()

void UpdateTileType ( NavmeshTile  tile)
private

Member Data Documentation

◆ activeTileOffsets

readonly int [] activeTileOffsets
private

Offsets along the Y axis of the active tiles.

◆ activeTileRotations

readonly int [] activeTileRotations
private

Rotations of the active tiles.

◆ activeTileTypes

readonly TileType [] activeTileTypes
private

Which tile type is active on each tile index.

This array will be tileXCount*tileZCount elements long.

◆ batchDepth

int batchDepth
private

Positive while batching tile updates.

Batching tile updates has a positive effect on performance

◆ cached_Int2_int_dict

readonly Dictionary<Int2, int> cached_Int2_int_dict = new Dictionary<Int2, int>()
private

Cached dictionary to avoid excessive allocations.

◆ clipper

readonly Clipper clipper = new Clipper()
private

Handles polygon clipping operations.

◆ cuts

readonly GridLookup<NavmeshClipper> cuts

NavmeshCut and NavmeshAdd components registered to this tile handler.

This is updated by the Pathfinding.NavmeshUpdates class.

See also
Pathfinding.NavmeshUpdates

◆ graph

readonly NavmeshBase graph

The underlaying graph which is handled by this instance.

◆ reloadedInBatch

readonly bool [] reloadedInBatch
private

A flag for each tile that is set to true if it has been reloaded while batching is in progress.

◆ simpleClipper

readonly Pathfinding.Voxels.Int3PolygonClipper simpleClipper
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

◆ tileXCount

readonly int tileXCount
private

Number of tiles along the x axis.

◆ tileZCount

readonly int tileZCount
private

Number of tiles along the z axis.

Property Documentation

◆ isBatching

bool isBatching
getprivate

True while batching tile updates.

Batching tile updates has a positive effect on performance

◆ isValid

bool isValid
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.


The documentation for this class was generated from the following file: