• Articles
  • Api Documentation
Show / Hide Table of Contents
  • AnyPath
    • Graphs
      • Extra
        • Line2D
        • Line3D
        • Triangle
      • HexGrid
        • HexGrid
        • HexGrid.Enumerator
        • HexGridCell
        • HexGridHeuristicProvider
        • HexGridType
      • Line
        • ClosestLineLocationPredicate
        • LineGraph
        • LineGraph.Edge
        • LineGraph.Enumerator
        • LineGraphBuilder
        • LineGraphBuilder.ProtoEdge
        • LineGraphDrawer
        • LineGraphHeuristic
        • LineGraphLocation
        • LineGraphPopulator
        • LineGraphProcessor
        • LineGraphWelder
        • SceneGraph
          • LineGraphNode
          • LineSceneGraph
          • LineSceneGraphEdge
          • SceneGraphNodeEditor
      • NavMesh
        • ClosestNavMeshLocationPredicate
        • CornerAndNormal
        • IUnrolledNavMeshGraphPortal
        • NavMeshGraph
        • NavMeshGraph.EnterCostAndFlags
        • NavMeshGraph.Enumerator
        • NavMeshGraphCorners
        • NavMeshGraphCorners3D
        • NavMeshGraphHeuristic
        • NavMeshGraphLocation
        • NavMeshGraphUnroller
        • NavMeshLineBitmaskMod
        • NavMeshLineMod
        • NavMeshPlaneBitmaskMod
        • NavMeshPlaneMod
        • NavMeshPopulator
        • NavMeshWelder
        • SSFA
        • UnrolledNavMeshGraphPortal
      • Node
        • NodeGraph
        • NodeGraphNode
      • PlatformerGraph
        • ClosestPlatformerGraphLocationPredicate
        • PlatformerGraph
        • PlatformerGraph.Enumerator
        • PlatformerGraphBuilder
        • PlatformerGraphBuilder.ProtoEdge
        • PlatformerGraphDrawer
        • PlatformerGraphHeuristic
        • PlatformerGraphLocation
        • PlatformerGraphPopulator
        • PlatformerGraphProcessor
        • PlatformerGraphWelder
        • SceneGraph
          • PlatformerSceneGraph
          • PlatformerSceneGraphEdge
          • PlatformerSceneGraphNode
          • SceneGraphNodeEditor
      • SquareGrid
        • SquareGrid
        • SquareGrid.Enumerator
        • SquareGridCell
        • SquareGridHeuristicProvider
        • SquareGridHeuristicProviderEightDirectional
        • SquareGridHeuristicProviderManhattanDistance
        • SquareGridType
      • VoxelGrid
        • VoxelGrid
        • VoxelGrid.DirCost
        • VoxelGrid.Enumerator
        • VoxelGridCell
        • VoxelGridDirectionFlags
        • VoxelGridDirectionMod
        • VoxelGridHeuristicProvider
        • VoxelGridHeuristicProviderManhattanDistance
    • Managed
      • ClearFinderFlags
      • FinderExtensions
      • IFinder
      • IOptionReserver<TOption>
      • IOptionValidator<TOption>
      • ImmutableFinderException
      • ManagedDisposeExtensions
      • Results
        • DijkstraResult<TNode>
        • Eval
        • Eval<TOption>
        • MultiEvalResult
        • MultiPathResult<TSeg>
        • Path<TSeg>
        • Path<TOption, TSeg>
    • Native
      • AStarCheapestOption
      • AStarEvalOptionResult
      • AStarEvalResult
      • AStarFindOptionResult
      • AStarFindPathResult
      • AStarOption
      • AStarStops
      • AStar<TNode>
      • ComposedGraph<TGraph, TNode>
      • Edge<TNode>
      • FlagBitmask<TNode>
      • IEdgeMod<TNode>
      • IGraph<TNode>
      • IHeuristicProvider<TNode>
      • INodeFlags
      • IPathProcessor<TNode, TSeg>
      • NativeListWrapper<TSeg>
      • NoEdgeMod<TNode>
      • NoProcessing<TNode>
      • OffsetInfo
      • ReversedGraph<TNode>
      • EdgeMods
        • AdditionalAndExcludeEdges<TNode>
        • AdditionalEdges<TNode>
        • ExcludeEdges<TNode>
        • ExcludeLocations<TNode>
      • Heuristics
        • ALTCompute<TGraph, TNode>
        • ALTSerialization
        • ALT<TNode>
        • LandmarkSelection<TGraph, TNode, TEnumerator>
      • Util
        • IRefComparer<T>
        • NativeMinHeap<T, TComp>
        • NativeRefMinHeap<T, TComp>

Struct VoxelGrid

A 3D voxel grid that's easily extendable with out of the box support for various movement types.

Implements
IGraph<VoxelGridCell>
IDisposable
Namespace: AnyPath.Graphs.VoxelGrid
Assembly: AnyPath.dll
Syntax
public struct VoxelGrid : IGraph<VoxelGridCell>, IDisposable

Constructors

VoxelGrid(int3, int3, DirCost[], Allocator, float, int, int)

Constructs a new grid.

Declaration
public VoxelGrid(int3 min, int3 max, VoxelGrid.DirCost[] directionsAndCost, Allocator allocator, float defaultCost = 0, int defaultFlags = 0, int capacity = 0)
Parameters
Type Name Description
int3 min

Boundary min

int3 max

Boundary max

DirCost[] directionsAndCost

Supported movement directions. Use any of the following:

  • Foward_Right_Back_Left_Up_Down
  • Foward_Right_Back_Left_Down_StairsUp
  • Foward_Right_Back_Left_Down_StairsUp_StairsDown
  • Eight_Up_Down
  • All26
Allocator allocator

Allocator to use

float defaultCost

The default cost to use for cells that are not set with any value

int defaultFlags

The default flags to use for cells that are not set with any value

int capacity

Initial capacity of the internal hashmap. If you know how many cells you are going to add beforehand, set it to this value for faster creation.

VoxelGrid(int3, int3, Allocator, float, int, int)

Constructs a new grid that supports straight 6 directional movement.

Declaration
public VoxelGrid(int3 min, int3 max, Allocator allocator, float defaultCost = 0, int defaultFlags = 0, int capacity = 0)
Parameters
Type Name Description
int3 min

Boundary min

int3 max

Boundary max

Allocator allocator

Allocator to use

float defaultCost

The default cost to use for cells that are not set with any value

int defaultFlags

The default flags to use for cells that are not set with any value

int capacity

Initial capacity of the internal hashmap. If you know how many cells you are going to add beforehand, set it to this value for faster creation.

VoxelGrid(int3, int3, NativeArray<DirCost>, Allocator, float, int, int)

Constructs a new grid. Can be used inside of jobs.

Declaration
public VoxelGrid(int3 min, int3 max, NativeArray<VoxelGrid.DirCost> directionsAndCost, Allocator allocator, float defaultCost, int defaultFlags, int capacity)
Parameters
Type Name Description
int3 min

Boundary min

int3 max

Boundary max

NativeArray<VoxelGrid.DirCost> directionsAndCost

Supported movement directions + associated costs. The supplied nativearray is copied.

Allocator allocator

Allocator to use

float defaultCost

The default cost to use for cells that are not set with any value

int defaultFlags

The default flags to use for cells that are not set with any value

int capacity

Initial capacity of the internal hashmap. If you know how many cells you are going to add beforehand, set it to this value for faster creation.

Fields

All26

All 26 directions are supported.

Declaration
public static readonly VoxelGrid.DirCost[] All26
Field Value
Type Description
DirCost[]

Eight_Up_Down

Allowed to move diagonally only when not going up or down. Up and down movement is only supported straight.

Declaration
public static readonly VoxelGrid.DirCost[] Eight_Up_Down
Field Value
Type Description
DirCost[]

Foward_Right_Back_Left_Down_StairsUp

Five straight directions: Forward, Right, Back, Left and Down Only allows upwards travel diagonally. Like walking "stairs".

Declaration
public static readonly VoxelGrid.DirCost[] Foward_Right_Back_Left_Down_StairsUp
Field Value
Type Description
DirCost[]

Foward_Right_Back_Left_Down_StairsUp_StairsDown

Five straight directions: Forward, Right, Back, Left and Down Supports diagonal movement up and down.

Declaration
public static readonly VoxelGrid.DirCost[] Foward_Right_Back_Left_Down_StairsUp_StairsDown
Field Value
Type Description
DirCost[]

Foward_Right_Back_Left_Up_Down

Default straight 6 directional movement.

Declaration
public static readonly VoxelGrid.DirCost[] Foward_Right_Back_Left_Up_Down
Field Value
Type Description
DirCost[]

max

The boundary -max- position

Declaration
public readonly int3 max
Field Value
Type Description
int3

min

The boundary -min- position

Declaration
public readonly int3 min
Field Value
Type Description
int3

Properties

DefaultCost

What (enter) cost to use for cells that have not been explicity set. When this is zero, this means that all open cells are navigatable by default.

One use case here is to make this float.PositiveInfinity. Then by default, no cells are navigatable. Only cells that are explicity set (for example, with a cost of zero) would be navigatable. In essence creating a "cave".

Declaration
public float DefaultCost { get; }
Property Value
Type Description
float

DefaultFlags

Flags to use for a cells that have not been explicity set.

Declaration
public int DefaultFlags { get; }
Property Value
Type Description
int

Methods

ClearCell(int3)

Clear a cell at a given position.

Declaration
public void ClearCell(int3 position)
Parameters
Type Name Description
int3 position
Remarks

The cell will be considered as unset again and the default cost and flags will be used for this position.

Collect(VoxelGridCell, ref NativeList<Edge<VoxelGridCell>>)

Collects all neighbouring cells from a given location

Declaration
public void Collect(VoxelGridCell node, ref NativeList<Edge<VoxelGridCell>> edgeBuffer)
Parameters
Type Name Description
VoxelGridCell node
NativeList<Edge<VoxelGridCell>> edgeBuffer

GetCell(int3)

Returns the cell at a given position.

Declaration
public VoxelGridCell GetCell(int3 position)
Parameters
Type Name Description
int3 position
Returns
Type Description
VoxelGridCell

GetCost(int3)

Returns the enter cost of a given position. Note that unset cells are considered open and have an entering cost of zero.

Declaration
public float GetCost(int3 position)
Parameters
Type Name Description
int3 position
Returns
Type Description
float

GetEnumerator()

Enumerates all of the cells in the grid, including unset ones. This can be used for constructing ALT heuristics.

Declaration
public VoxelGrid.Enumerator GetEnumerator()
Returns
Type Description
VoxelGrid.Enumerator
Remarks

Be cautious as a 3D grid contains a lot of positions. I don't advise to use ALT heuristics on large 3D grids.

GetSetCells(Allocator)

Allocates an array containing all of the cells that are explicity set on this grid.

Declaration
public NativeArray<VoxelGridCell> GetSetCells(Allocator allocator)
Parameters
Type Name Description
Allocator allocator
Returns
Type Description
NativeArray<VoxelGridCell>

InBounds(int3)

Returns wether a certain position is within the bounds of the grid

Declaration
public bool InBounds(int3 position)
Parameters
Type Name Description
int3 position
Returns
Type Description
bool

SetCell(int3, float, int)

Sets the cost for a cell.

Declaration
public void SetCell(int3 position, float enterCost, int flags = 0)
Parameters
Type Name Description
int3 position

Position to set

float enterCost

Additional cost for walking this cell. Use float.PositiveInfinity to make this cell unwalkable

int flags

Flags for this cell, this can be used in conjunction with FlagBitmask<TNode> to exclude certain areas.

Remarks

No bounds checking is done on the position

Implements

IGraph<TNode>
IDisposable

Extension Methods

FinderExtensions.AddOption<T, TNode, TOption>(T, TOption, TNode, TNode)
FinderExtensions.AddOptions<T, TNode, TOption>(T, IEnumerable<TOption>, TNode, Func<TOption, TNode>)
FinderExtensions.AddRange<T, TNode, TOption>(T, IEnumerable<TOption>, TNode, Func<TOption, TNode>)
FinderExtensions.AddRequest<T, TNode>(T, TNode, TNode)
FinderExtensions.AddRequests<T, TNode>(T, IEnumerable<TNode>)
FinderExtensions.AddStop<T, TNode>(T, TNode)
FinderExtensions.AddStops<T, TNode>(T, IEnumerable<TNode>)
FinderExtensions.SetComparer<T, TOption>(T, IComparer<TOption>)
FinderExtensions.SetEdgeMod<T, TMod>(T, TMod)
FinderExtensions.SetGraph<T, TGraph>(T, TGraph)
FinderExtensions.SetHeuristicProvider<T, TH>(T, TH)
FinderExtensions.SetPathProcessor<T, TProc>(T, TProc)
FinderExtensions.SetReserver<T, TOption>(T, IOptionReserver<TOption>)
FinderExtensions.SetStartAndGoal<T, TNode>(T, TNode, TNode)
FinderExtensions.SetValidator<T, TOption>(T, IOptionValidator<TOption>)
ManagedDisposeExtensions.DisposeGraph<TGraph>(TGraph)
In This Article
Back to top Generated by DocFX