A* Pathfinding Project  3.8.8
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
Voxelize Class Reference

Voxelizer for recast graphs. More...

Detailed Description

Voxelizer for recast graphs.

In comments: units wu are World Units, vx are Voxels

A* Pro Feature:
This is an A* Pathfinding Project Pro feature only. This function/class/variable might not exist in the Free version of the A* Pathfinding Project or the functionality might be limited
The Pro version can be bought here

Public Member Functions

 Voxelize (float ch, float cs, float wc, float wh, float ms)
 
ushort[] BoxBlur (ushort[] src, ushort[] dst)
 
void BuildCompactField ()
 
void BuildContours (float maxError, int maxEdgeLength, VoxelContourSet cset, int buildFlags)
 
void BuildDistanceField ()
 
void BuildPolyMesh (VoxelContourSet cset, int nvp, out VoxelMesh mesh)
 Builds a polygon mesh from a contour set.
 
void BuildRegions ()
 
void BuildVoxelConnections ()
 
int CalcAreaOfPolygon2D (int[] verts, int nverts)
 
ushort CalculateDistanceField (ushort[] src)
 
void CollectMeshes ()
 
Vector3 CompactSpanToVector (int x, int z, int i)
 
void DebugDrawCompactSpans ()
 
void DebugDrawSpans ()
 
void ErodeVoxels (int radius)
 
void ErodeWalkableArea (int radius)
 
ushort[] ExpandRegions (int maxIterations, uint level, ushort[] srcReg, ushort[] srcDist, ushort[] dstReg, ushort[] dstDist, List< int > stack)
 
void FilterLedges (uint voxelWalkableHeight, int voxelWalkableClimb, float cs, float ch, Vector3 min)
 
void FilterLowHeightSpans (uint voxelWalkableHeight, float cs, float ch, Vector3 min)
 
void FilterSmallRegions (ushort[] reg, int minRegionSize, int maxRegions)
 Filters out or merges small regions.
 
bool FloodRegion (int x, int z, int i, uint level, ushort r, ushort[] srcReg, ushort[] srcDist, List< int > stack)
 
int GetCornerHeight (int x, int z, int i, int dir, ref bool isBorderVertex)
 
void Init ()
 
void MarkRectWithRegion (int minx, int maxx, int minz, int maxz, ushort region, ushort[] srcReg)
 
void OnGUI ()
 
void RemoveDegenerateSegments (List< int > simplified)
 
void SimplifyContour (List< int > verts, List< int > simplified, float maxError, int maxEdgeLenght, int buildFlags)
 
void VectorToIndex (Vector3 p, out int x, out int z)
 
void VoxelizeInput ()
 
void WalkContour (int x, int z, int i, ushort[] flags, List< int > verts)
 

Static Public Member Functions

static int Area2 (int a, int b, int c, int[] verts)
 
static void CollectMeshes (List< ExtraMesh > extraMeshes, Bounds bounds, out Vector3[] verts, out int[] tris)
 
static bool Collinear (int a, int b, int c, int[] verts)
 
static bool Diagonal (int i, int j, int n, int[] verts, int[] indices)
 Returns T iff (v_i, v_j) is a proper internal diagonal of P.
 
static bool Ileft (int a, int b, int c, int[] va, int[] vb, int[] vc)
 
static bool InCone (int i, int j, int n, int[] verts, int[] indices)
 
static bool IntersectProp (int a, int b, int c, int d, int[] verts)
 
static bool Left (int a, int b, int c, int[] verts)
 Returns true iff c is strictly to the left of the directed line through a to b.
 
static bool LeftOn (int a, int b, int c, int[] verts)
 
static bool MergeContours (ref VoxelContour ca, ref VoxelContour cb, int ia, int ib)
 
static int Next (int i, int n)
 (i+1) % n assuming 0 <= i < n
 
static int Prev (int i, int n)
 (i-1+n) % n assuming 0 <= i < n
 
static bool Xorb (bool x, bool y)
 

Public Attributes

int borderSize = 0
 The size of the non-navigable border around the heightfield.
 
readonly float cellHeight = 0.1F
 The y-axis cell size to use for fields.
 
readonly Vector3 cellScale
 
readonly Vector3 cellScaleDivision
 
readonly float cellSize = 0.2F
 The xz-plane cell size to use for fields.
 
VoxelContourSet countourSet
 
string debugString = ""
 
int depth
 Depth in voxels.
 
Bounds forcedBounds
 The world AABB to rasterize.
 
List< ExtraMeshinputExtraMeshes
 
float maxEdgeLength = 20
 The maximum allowed length for contour edges along the border of the mesh.
 
float maxSlope = 30
 The maximum slope that is considered walkable.
 
int minRegionSize = 100
 
RecastGraph.RelevantGraphSurfaceMode relevantGraphSurfaceMode
 
VoxelArea voxelArea
 
Vector3 voxelOffset
 
readonly int voxelWalkableClimb
 Maximum ledge height that is considered to still be traversable.
 
readonly uint voxelWalkableHeight
 Minimum floor to 'ceiling' height that will still allow the floor area to be considered walkable.
 
int width
 Width in voxels.
 
Constants @{
const uint NotConnected = 0x3f
 
const int MaxLayers = 65535
 Unmotivated variable, but let's clamp the layers at 65535.
 
const int MaxRegions = 500
 
const int UnwalkableArea = 0
 
const ushort BorderReg = 0x8000
 If heightfield region ID has the following bit set, the region is on border area and excluded from many calculations.
 
const int RC_BORDER_VERTEX = 0x10000
 If contour region ID has the following bit set, the vertex will be later removed in order to match the segments and vertices at tile boundaries.
 
const int RC_AREA_BORDER = 0x20000
 
const int VERTEX_BUCKET_COUNT = 1<<12
 
const int RC_CONTOUR_TESS_WALL_EDGES = 0x01
 
const int RC_CONTOUR_TESS_AREA_EDGES = 0x02
 
const int ContourRegMask = 0xffff
 Mask used with contours to extract region id.
 

Protected Attributes

int[] inputTriangles
 
Vector3[] inputVertices
 

Private Member Functions

Vector3 ConvertPos (int x, int y, int z)
 
Vector3 ConvertPosCorrZ (int x, int y, int z)
 
Vector3 ConvertPosition (int x, int z, int i)
 
Vector3 ConvertPosWithoutOffset (int x, int y, int z)
 
void DrawLine (int a, int b, int[] indices, int[] verts, Color col)
 
void FloodOnes (List< Int3 > st1, ushort[] regs, uint level, ushort reg)
 
void GetClosestIndices (int[] vertsa, int nvertsa, int[] vertsb, int nvertsb, ref int ia, ref int ib)
 
int Triangulate (int n, int[] verts, ref int[] indices, ref int[] tris)
 

Static Private Member Functions

static bool Between (int a, int b, int c, int[] verts)
 
static int[] ClaimIntArr (int minCapacity, bool zero)
 
static bool Diagonalie (int i, int j, int n, int[] verts, int[] indices)
 Returns T iff (v_i, v_j) is a proper internal *or* external diagonal of P, *ignoring edges incident to v_i and v_j*.
 
static bool Intersect (int a, int b, int c, int d, int[] verts)
 
static void ReleaseContours (VoxelContourSet cset)
 Releases contents of a contour set to caches.
 
static void ReleaseIntArr (int[] arr)
 
static int union_find_find (int[] arr, int x)
 
static void union_find_union (int[] arr, int a, int b)
 
static bool Vequal (int a, int b, int[] verts)
 

Static Private Attributes

static readonly int[] emptyArr = new int[0]
 
static List< int[]> intArrCache = new List<int[]>()
 

Constructor & Destructor Documentation

Voxelize ( float  ch,
float  cs,
float  wc,
float  wh,
float  ms 
)

Member Function Documentation

static int Area2 ( int  a,
int  b,
int  c,
int[]  verts 
)
static
static bool Between ( int  a,
int  b,
int  c,
int[]  verts 
)
staticprivate
ushort [] BoxBlur ( ushort[]  src,
ushort[]  dst 
)
void BuildCompactField ( )
void BuildContours ( float  maxError,
int  maxEdgeLength,
VoxelContourSet  cset,
int  buildFlags 
)
void BuildDistanceField ( )
void BuildPolyMesh ( VoxelContourSet  cset,
int  nvp,
out VoxelMesh  mesh 
)

Builds a polygon mesh from a contour set.

Parameters
csetcontour set to build a mesh from.
nvpMaximum allowed vertices per polygon.
Warning
Currently locked to 3.
Parameters
meshResults will be written to this mesh.
void BuildRegions ( )
void BuildVoxelConnections ( )
int CalcAreaOfPolygon2D ( int[]  verts,
int  nverts 
)
ushort CalculateDistanceField ( ushort[]  src)
static int [] ClaimIntArr ( int  minCapacity,
bool  zero 
)
staticprivate
void CollectMeshes ( )
static void CollectMeshes ( List< ExtraMesh extraMeshes,
Bounds  bounds,
out Vector3[]  verts,
out int[]  tris 
)
static
static bool Collinear ( int  a,
int  b,
int  c,
int[]  verts 
)
static
Vector3 CompactSpanToVector ( int  x,
int  z,
int  i 
)
Vector3 ConvertPos ( int  x,
int  y,
int  z 
)
private
Vector3 ConvertPosCorrZ ( int  x,
int  y,
int  z 
)
private
Vector3 ConvertPosition ( int  x,
int  z,
int  i 
)
private
Vector3 ConvertPosWithoutOffset ( int  x,
int  y,
int  z 
)
private
void DebugDrawCompactSpans ( )
void DebugDrawSpans ( )
static bool Diagonal ( int  i,
int  j,
int  n,
int[]  verts,
int[]  indices 
)
static

Returns T iff (v_i, v_j) is a proper internal diagonal of P.

static bool Diagonalie ( int  i,
int  j,
int  n,
int[]  verts,
int[]  indices 
)
staticprivate

Returns T iff (v_i, v_j) is a proper internal *or* external diagonal of P, *ignoring edges incident to v_i and v_j*.

void DrawLine ( int  a,
int  b,
int[]  indices,
int[]  verts,
Color  col 
)
private
void ErodeVoxels ( int  radius)
Todo:
Complete the ErodeVoxels function translation
void ErodeWalkableArea ( int  radius)
ushort [] ExpandRegions ( int  maxIterations,
uint  level,
ushort[]  srcReg,
ushort[]  srcDist,
ushort[]  dstReg,
ushort[]  dstDist,
List< int >  stack 
)
void FilterLedges ( uint  voxelWalkableHeight,
int  voxelWalkableClimb,
float  cs,
float  ch,
Vector3  min 
)
void FilterLowHeightSpans ( uint  voxelWalkableHeight,
float  cs,
float  ch,
Vector3  min 
)
void FilterSmallRegions ( ushort[]  reg,
int  minRegionSize,
int  maxRegions 
)

Filters out or merges small regions.

void FloodOnes ( List< Int3 st1,
ushort[]  regs,
uint  level,
ushort  reg 
)
private
bool FloodRegion ( int  x,
int  z,
int  i,
uint  level,
ushort  r,
ushort[]  srcReg,
ushort[]  srcDist,
List< int >  stack 
)
void GetClosestIndices ( int[]  vertsa,
int  nvertsa,
int[]  vertsb,
int  nvertsb,
ref int  ia,
ref int  ib 
)
private
int GetCornerHeight ( int  x,
int  z,
int  i,
int  dir,
ref bool  isBorderVertex 
)
static bool Ileft ( int  a,
int  b,
int  c,
int[]  va,
int[]  vb,
int[]  vc 
)
static
static bool InCone ( int  i,
int  j,
int  n,
int[]  verts,
int[]  indices 
)
static
void Init ( )
static bool Intersect ( int  a,
int  b,
int  c,
int  d,
int[]  verts 
)
staticprivate
static bool IntersectProp ( int  a,
int  b,
int  c,
int  d,
int[]  verts 
)
static
static bool Left ( int  a,
int  b,
int  c,
int[]  verts 
)
static

Returns true iff c is strictly to the left of the directed line through a to b.

static bool LeftOn ( int  a,
int  b,
int  c,
int[]  verts 
)
static
void MarkRectWithRegion ( int  minx,
int  maxx,
int  minz,
int  maxz,
ushort  region,
ushort[]  srcReg 
)
static bool MergeContours ( ref VoxelContour  ca,
ref VoxelContour  cb,
int  ia,
int  ib 
)
static
static int Next ( int  i,
int  n 
)
static

(i+1) % n assuming 0 <= i < n

void OnGUI ( )
static int Prev ( int  i,
int  n 
)
static

(i-1+n) % n assuming 0 <= i < n

static void ReleaseContours ( VoxelContourSet  cset)
staticprivate

Releases contents of a contour set to caches.

static void ReleaseIntArr ( int[]  arr)
staticprivate
void RemoveDegenerateSegments ( List< int >  simplified)
void SimplifyContour ( List< int >  verts,
List< int >  simplified,
float  maxError,
int  maxEdgeLenght,
int  buildFlags 
)
int Triangulate ( int  n,
int[]  verts,
ref int[]  indices,
ref int[]  tris 
)
private
static int union_find_find ( int[]  arr,
int  x 
)
staticprivate
static void union_find_union ( int[]  arr,
int  a,
int  b 
)
staticprivate
void VectorToIndex ( Vector3  p,
out int  x,
out int  z 
)
static bool Vequal ( int  a,
int  b,
int[]  verts 
)
staticprivate
void VoxelizeInput ( )
void WalkContour ( int  x,
int  z,
int  i,
ushort[]  flags,
List< int >  verts 
)
static bool Xorb ( bool  x,
bool  y 
)
static

Member Data Documentation

const ushort BorderReg = 0x8000

If heightfield region ID has the following bit set, the region is on border area and excluded from many calculations.

int borderSize = 0

The size of the non-navigable border around the heightfield.

[Limit: >=0] [Units: vx]

readonly float cellHeight = 0.1F

The y-axis cell size to use for fields.

[Limit: > 0] [Units: wu]

readonly Vector3 cellScale
readonly Vector3 cellScaleDivision
readonly float cellSize = 0.2F

The xz-plane cell size to use for fields.

[Limit: > 0] [Units: wu]

const int ContourRegMask = 0xffff

Mask used with contours to extract region id.

VoxelContourSet countourSet
string debugString = ""
int depth

Depth in voxels.

Must match the forcedBounds

readonly int [] emptyArr = new int[0]
staticprivate
Bounds forcedBounds

The world AABB to rasterize.

List<ExtraMesh> inputExtraMeshes
int [] inputTriangles
protected
Vector3 [] inputVertices
protected
List<int[]> intArrCache = new List<int[]>()
staticprivate
float maxEdgeLength = 20

The maximum allowed length for contour edges along the border of the mesh.

[Limit: >= 0] [Units: vx]

const int MaxLayers = 65535

Unmotivated variable, but let's clamp the layers at 65535.

const int MaxRegions = 500
Todo:
: Check up on this variable
float maxSlope = 30

The maximum slope that is considered walkable.

[Limits: 0 <= value < 90] [Units: Degrees]

int minRegionSize = 100
const uint NotConnected = 0x3f
const int RC_AREA_BORDER = 0x20000
const int RC_BORDER_VERTEX = 0x10000

If contour region ID has the following bit set, the vertex will be later removed in order to match the segments and vertices at tile boundaries.

const int RC_CONTOUR_TESS_AREA_EDGES = 0x02
const int RC_CONTOUR_TESS_WALL_EDGES = 0x01
RecastGraph.RelevantGraphSurfaceMode relevantGraphSurfaceMode
const int UnwalkableArea = 0
const int VERTEX_BUCKET_COUNT = 1<<12
VoxelArea voxelArea
Vector3 voxelOffset
readonly int voxelWalkableClimb

Maximum ledge height that is considered to still be traversable.

[Limit: >=0] [Units: vx]

readonly uint voxelWalkableHeight

Minimum floor to 'ceiling' height that will still allow the floor area to be considered walkable.

[Limit: >= 3] [Units: vx]

int width

Width in voxels.

Must match the forcedBounds


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