Utility class for updating tiles of navmesh/recast graphs.
More...
Utility class for updating tiles of navmesh/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.
- See Also
- TileHandlerHelper
|
| TileHandler (NavmeshBase graph) |
|
void | ClearTile (int x, int z) |
| Clear the tile at the specified tile coordinates.
|
|
void | CreateTileTypesFromGraph () |
|
void | EndBatchLoad () |
|
int | GetActiveRotation (Int2 p) |
| Rotation of the specified tile relative to the original rotation of the tile type.
|
|
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 (NavmeshTile[] recalculatedTiles) |
| Call to update the specified tiles with new information based on the navmesh/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 bounds) |
| Reloads all tiles intersecting with the specified bounds.
|
|
void | ReloadInBounds (IntRect tiles) |
| Reloads all tiles specified by the rectangle.
|
|
void | ReloadTile (int x, int z) |
| Reload tile at tile coordinate.
|
|
bool | StartBatchLoad () |
| Start batch loading.
|
|
|
bool | isValid [get] |
| True if the tile handler still has the same number of tiles and tile layout as the graph.
|
|
|
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 | 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.
|
|
void | DelaunayRefinement (Int3[] verts, int[] tris, ref int tCount, bool delaunay, bool colinear) |
| Refine a mesh using delaunay refinement.
|
|
void | UpdateTileType (NavmeshTile tile) |
|
|
static void | CopyMesh (Int3[] vertices, int[] triangles, List< Int3 > outVertices, List< int > outTriangles) |
| Copy mesh from (vertices, triangles) to (outVertices, outTriangles)
|
|
static void | PoolPolygon (Poly2Tri.Polygon polygon, Stack< Poly2Tri.Polygon > pool) |
|
static List< Cut > | PrepareNavmeshCutsForCutting (List< NavmeshCut > navmeshCuts, GraphTransform transform, IntRect cutSpaceBounds, 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.
|
|
- 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.
|
void ClearTile |
( |
int |
x, |
|
|
int |
z |
|
) |
| |
Clear the tile at the specified tile coordinates.
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
-
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. |
- Returns
- Number of output vertices
static void CopyMesh |
( |
Int3[] |
vertices, |
|
|
int[] |
triangles, |
|
|
List< Int3 > |
outVertices, |
|
|
List< int > |
outTriangles |
|
) |
| |
|
staticprivate |
Copy mesh from (vertices, triangles) to (outVertices, outTriangles)
void CreateTileTypesFromGraph |
( |
| ) |
|
void CutAll |
( |
List< IntPoint > |
poly, |
|
|
List< int > |
intersectingCutIndices, |
|
|
List< Cut > |
cuts, |
|
|
Pathfinding.ClipperLib.PolyTree |
result |
|
) |
| |
|
private |
void CutDual |
( |
List< IntPoint > |
poly, |
|
|
List< int > |
tmpIntersectingCuts, |
|
|
List< Cut > |
cuts, |
|
|
bool |
hasDual, |
|
|
List< List< IntPoint > > |
intermediateResult, |
|
|
Pathfinding.ClipperLib.PolyTree |
result |
|
) |
| |
|
private |
void CutExtra |
( |
List< IntPoint > |
poly, |
|
|
List< IntPoint > |
extraClipShape, |
|
|
Pathfinding.ClipperLib.PolyTree |
result |
|
) |
| |
|
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
-
verts | Vertices that are going to be cut. Should be in graph space. |
tris | Triangles describing a mesh using the vertices. |
extraShape | If supplied the resulting mesh will be the intersection of the input mesh and this mesh. |
graphTransform | Transform mapping graph space to world space. |
- See Also
- NavmeshBase.transform
- Parameters
-
tiles | Tiles in the recast graph which the mesh covers. |
mode | |
- See Also
- CutMode
- Parameters
-
perturbate | Move 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. |
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
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.
void LoadTile |
( |
TileType |
tile, |
|
|
int |
x, |
|
|
int |
z, |
|
|
int |
rotation, |
|
|
int |
yoffset |
|
) |
| |
Load a tile at tile coordinate x, z.
- Parameters
-
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 |
( |
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.
static void PoolPolygon |
( |
Poly2Tri.Polygon |
polygon, |
|
|
Stack< Poly2Tri.Polygon > |
pool |
|
) |
| |
|
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.
TileType RegisterTileType |
( |
Mesh |
source, |
|
|
Int3 |
centerOffset, |
|
|
int |
width = 1 , |
|
|
int |
depth = 1 |
|
) |
| |
Register that a tile can be loaded from source.
- Parameters
-
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. |
- Returns
- Identifier for loading that tile type
void ReloadInBounds |
( |
Bounds |
bounds | ) |
|
Reloads all tiles intersecting with the specified bounds.
void ReloadInBounds |
( |
IntRect |
tiles | ) |
|
Reloads all tiles specified by the rectangle.
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.
- Returns
- The interpolated y coordinate unless the triangle is degenerate in which case a DivisionByZeroException will be thrown
- See Also
- https://en.wikipedia.org/wiki/Barycentric_coordinate_system
Start batch loading.
- Returns
- True if batching wasn't started yet, and thus EndBatchLoad should be called, False if batching was already started by some other part of the code and you should not call EndBatchLoad
readonly int [] activeTileOffsets |
|
private |
Offsets along the Y axis of the active tiles.
readonly int [] activeTileRotations |
|
private |
Rotations of the active tiles.
Which tile type is active on each tile index.
This array will be tileXCount*tileZCount elements long.
readonly Dictionary<Int2, int> cached_Int2_int_dict = new Dictionary<Int2, int>() |
|
private |
Cached dictionary to avoid excessive allocations.
readonly Clipper clipper = new Clipper() |
|
private |
Handles polygon clipping operations.
The underlaying graph which is handled by this instance.
True while batching tile updates.
Batching tile updates has a positive effect on performance
readonly bool [] reloadedInBatch |
|
private |
A flag for each tile that is set to true if it has been reloaded while batching is in progress.
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
Number of tiles along the x axis.
Number of tiles along the z axis.
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:
- /Users/arong/Unity/a-pathfinding-project/Assets/AstarPathfindingProject/Generators/Utilities/TileHandler.cs