Photon Quantum 3.0.0

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Quantum.NavMesh Class Reference

The asset object that contains a Quantum navigation mesh. The object loads an additional data file during the Loaded. This is because of size limitations when loading the data with Unity serialization. More...

Public Member Functions

void ClampToGrid (ref FPVector2 position)
 Clamps the position to be on the grid. More...
 
void ClampToGrid (ref FPVector3 position)
 Clamps the position to be on the grid. More...
 
Boolean Contains (FPVector3 position, NavMeshRegionMask regionMask, bool inclusive=false)
 Checks if the position is on a navmesh triangle. Does only check the 2D coordinates. More...
 
bool FindClosestTriangle (FPVector3 sourcePosition, FP radius, NavMeshRegionMask regionMask, out Int32 triangle, out FPVector3 closestPosition, MailboxSet8 mailbox=null)
 Finds the closest navmesh triangle at the position plus radius. Works in 2D and 3D. Caveat: The result is only a heuristic and not 100% accurate due to simplified calculations to reduce precision issues. For example: in 3D the input position is projected down instead of finding the correct closest position. The search can be performance heavy so carefully choose the radius. More...
 
bool FindClosestTriangle (FrameBase frame, FPVector3 sourcePosition, FP radius, NavMeshRegionMask regionMask, out Int32 triangle, out FPVector3 closestPosition)
 Finds the closest navmesh triangle at the position plus radius. Works in 2D and 3D. This method sets the mailboxing optimization internally which requires the frame object. Otherwise it's identical to NavMesh.FindClosestTriangle(FPVector3, FP, NavMeshRegionMask, out int, out FPVector3, MailboxSet8). Caveat: The result is only a heuristic and not 100% accurate due to simplified calculations to reduce precision issues. For example: in 3D the input position is projected down instead of finding the correct closest position. The search can be performance heavy so carefully choose the radius. More...
 
bool FindClosestTriangle (FrameThreadSafe frame, FPVector3 sourcePosition, FP radius, NavMeshRegionMask regionMask, out Int32 triangle, out FPVector3 closestPosition)
 Finds the closest navmesh triangle at the position plus radius. Works in 2D and 3D. This method sets the mailboxing optimization internally which requires the frame object. Otherwise it's identical to NavMesh.FindClosestTriangle(FPVector3, FP, NavMeshRegionMask, out int, out FPVector3, MailboxSet8). Caveat: The result is only a heuristic and not 100% accurate due to simplified calculations to reduce precision issues. For example: in 3D the input position is projected down instead of finding the correct closest position. The search can be performance heavy so carefully choose the radius. More...
 
Int32 FindClosestTriangleFast (FPVector3 position, NavMeshRegionMask regionMask)
 Searches the closest triangle to the input position by using the fallback triangle saved for each grid cell. Result is quite inaccurate. More...
 
bool FindRandomPointOnNavmesh (FPVector3 position, FP radius, RNGSession *rngSession, NavMeshRegionMask regionMask, out FPVector3 result)
 Tries to find a random position on the navmesh using the input position and radius. This can fail when there is no navmesh in range. More...
 
bool FindRandomPointOnTriangle (Int32 triangle, RNGSession *rngSession, out FPVector3 result)
 Generates a random point on the triangle. More...
 
Int32 FindTriangle2D (FPVector3 position, NavMeshRegionMask regionMask, bool inclusive=false)
 Finds the triangle at position (X,Z). This will not work in 3D as overlapping triangles may occur. Always use FindClosestTriangle() in 3D. More...
 
bool IsBorderActive (int borderIndex, NavMeshRegionMask regionMask)
 Test if the region of the border at index is enabled. More...
 
override void Loaded (IResourceManager assets, Native.Allocator allocator)
 Checks the DataAsset to load the additional data and runs Serialize(ByteStream, bool) to deserialize the navmesh data. More...
 
unsafe FPVector2 MovePositionIntoNavmesh (FrameBase frame, FPVector2 position, FPVector2 newPosition, FP correction, NavMeshRegionMask regionMask)
 This performs a correction of the agent movement against the navmesh borders much like solving physics contacts. This works only in 2D for now. Used internally if NavMeshAgentConfig.ClampAgentToNavmesh is set. More...
 
unsafe FPVector2 MovePositionIntoNavmesh (FrameThreadSafe frame, FPVector2 position, FPVector2 newPosition, FP correction, NavMeshRegionMask regionMask)
 This performs a correction of the agent movement against the navmesh borders much like solving physics contacts. This works only in 2D for now. Used internally if NavMeshAgentConfig.ClampAgentToNavmesh is set. More...
 
void Serialize (ByteStream stream, Boolean write)
 Serializes internal data structures (Triangles, TrianglesGrid, Vertices, BorderGrid, TrianglesCenterGrid, Regions, Borders) from the byte stream. Called during . More...
 

Static Public Member Functions

static Int64 GetHeightAtTriangleRaw (FPVector3 p, FPVector3 normal, FPVector3 v0)
 Returns the y-component of the triangle at point p. Does not check if the point is actually on the XZ-dimensions of the triangle. Projects the exact XZ position and does not find the closet position inside the triangle. More...
 

Public Attributes

NavMeshBakeData BakeData = new NavMeshBakeData()
 The BakeData of this navmesh, only used when serialization type is NavMeshSerializeType.BakeDataOnly. More...
 
Int32 BorderCount => Borders?.Length ?? 0
 Gets the number of borders. More...
 
NavMeshBorderNode[] BorderGrid
 Per grid cell data structure that holds all indices to borders inside this cell. More...
 
NavMeshBorder[] Borders
 Navmesh borders. More...
 
AssetRef< BinaryDataDataAsset
 Asset that contains the actual binary navmesh data. More...
 
Int32 GridNodeSize
 The number of units one grid cell has in both dimensions. Minimum 2. Must be an even number. Derived from the map values during baking. More...
 
Int32 GridSizeX
 The navmesh triangles are partitioned by simple 2D grid. This is the number of all cells on the x-axis. Derived from the map values during baking. More...
 
Int32 GridSizeY
 The number of all grid cells on the y-axis. Derived from the map values during baking. More...
 
NavMeshLink[] Links
 All extra triangle connections on the navmesh called links. More...
 
FP MinAgentRadius
 The smallest agent radius that the navmesh was created for (to pass visually nicely around the corners). More...
 
String Name
 Name of the navmesh. Access the navmesh by name through Map.NavMeshes. More...
 
NavMeshSerializeType SerializeType
 How the NavMesh should be serialized. More...
 
NavMeshTriangle[] Triangles
 Navmesh triangles. More...
 
NavMeshTriangleCenterGridNode[] TrianglesCenterGrid
 Per grid cell data structure that holds one (multiple if regions are used) triangle that is somewhat closest to the grid center as a fallback triangle lookup. More...
 
NavMeshTriangleNode[] TrianglesGrid
 Per grid cell data structure that holds all indices to triangles inside this cell. More...
 
NavMeshVertex[] Vertices
 Navmesh vertices referenced by triangles. More...
 
FPVector2 WorldOffset
 The center of the map is the origin. The world offset represents the lower left corner and is copied from Map during the navmesh baking. More...
 

Detailed Description

The asset object that contains a Quantum navigation mesh. The object loads an additional data file during the Loaded. This is because of size limitations when loading the data with Unity serialization.

Member Function Documentation

◆ Loaded()

override void Quantum.NavMesh.Loaded ( IResourceManager  assets,
Native.Allocator  allocator 
)
inline

Checks the DataAsset to load the additional data and runs Serialize(ByteStream, bool) to deserialize the navmesh data.

Parameters
assetsThe resource manager to access other assets
allocatorThe allocator to allocate additional memory for this asset

◆ ClampToGrid() [1/2]

void Quantum.NavMesh.ClampToGrid ( ref FPVector2  position)
inline

Clamps the position to be on the grid.

Parameters
positionWorld position

◆ ClampToGrid() [2/2]

void Quantum.NavMesh.ClampToGrid ( ref FPVector3  position)
inline

Clamps the position to be on the grid.

Parameters
positionWorld position

◆ GetHeightAtTriangleRaw()

static Int64 Quantum.NavMesh.GetHeightAtTriangleRaw ( FPVector3  p,
FPVector3  normal,
FPVector3  v0 
)
inlinestatic

Returns the y-component of the triangle at point p. Does not check if the point is actually on the XZ-dimensions of the triangle. Projects the exact XZ position and does not find the closet position inside the triangle.

Parameters
pPoint to project to triangle
normalTriangle normal
v0Point in triangle
Returns
Height at point in triangle as raw value.

◆ FindClosestTriangle() [1/3]

bool Quantum.NavMesh.FindClosestTriangle ( FrameThreadSafe  frame,
FPVector3  sourcePosition,
FP  radius,
NavMeshRegionMask  regionMask,
out Int32  triangle,
out FPVector3  closestPosition 
)
inline

Finds the closest navmesh triangle at the position plus radius. Works in 2D and 3D. This method sets the mailboxing optimization internally which requires the frame object. Otherwise it's identical to NavMesh.FindClosestTriangle(FPVector3, FP, NavMeshRegionMask, out int, out FPVector3, MailboxSet8). Caveat: The result is only a heuristic and not 100% accurate due to simplified calculations to reduce precision issues. For example: in 3D the input position is projected down instead of finding the correct closest position. The search can be performance heavy so carefully choose the radius.

Parameters
frameFrame object to locate mailbox memory
sourcePositionPosition to start looking
radiusSearch radius around starting position. Use FP.0 to only search at the exact input position.
regionMaskRegion mask
triangleThe resulting triangle id
closestPositionThe corrected source position on the navmesh
Returns
true when a triangle was found

◆ FindClosestTriangle() [2/3]

bool Quantum.NavMesh.FindClosestTriangle ( FrameBase  frame,
FPVector3  sourcePosition,
FP  radius,
NavMeshRegionMask  regionMask,
out Int32  triangle,
out FPVector3  closestPosition 
)
inline

Finds the closest navmesh triangle at the position plus radius. Works in 2D and 3D. This method sets the mailboxing optimization internally which requires the frame object. Otherwise it's identical to NavMesh.FindClosestTriangle(FPVector3, FP, NavMeshRegionMask, out int, out FPVector3, MailboxSet8). Caveat: The result is only a heuristic and not 100% accurate due to simplified calculations to reduce precision issues. For example: in 3D the input position is projected down instead of finding the correct closest position. The search can be performance heavy so carefully choose the radius.

Parameters
frameFrame object to locate mailbox memory
sourcePositionPosition to start looking
radiusSearch radius around starting position. Use FP.0 to only search at the exact input position.
regionMaskRegion mask
triangleThe resulting triangle id
closestPositionThe corrected source position on the navmesh
Returns
true when a triangle was found

◆ FindClosestTriangle() [3/3]

bool Quantum.NavMesh.FindClosestTriangle ( FPVector3  sourcePosition,
FP  radius,
NavMeshRegionMask  regionMask,
out Int32  triangle,
out FPVector3  closestPosition,
MailboxSet8  mailbox = null 
)
inline

Finds the closest navmesh triangle at the position plus radius. Works in 2D and 3D. Caveat: The result is only a heuristic and not 100% accurate due to simplified calculations to reduce precision issues. For example: in 3D the input position is projected down instead of finding the correct closest position. The search can be performance heavy so carefully choose the radius.

Parameters
sourcePositionPosition to start looking
radiusSearch radius around starting position. Use FP.0 to only search at the exact input position (don't use for 3D).
regionMaskRegion mask
triangleThe resulting triangle id
closestPositionThe corrected source position on the navmesh
mailboxOptionally add a mailbox data structure to optimize the performance of search by filtering out already checked triangles.
Returns
true when a triangle was found

◆ FindTriangle2D()

Int32 Quantum.NavMesh.FindTriangle2D ( FPVector3  position,
NavMeshRegionMask  regionMask,
bool  inclusive = false 
)
inline

Finds the triangle at position (X,Z). This will not work in 3D as overlapping triangles may occur. Always use FindClosestTriangle() in 3D.

Parameters
positionSample position
regionMaskRegion mask
inclusiveUse inclusive true when you want include the border and the vertices of the triangle
Returns
Triangle id or -1

◆ FindClosestTriangleFast()

Int32 Quantum.NavMesh.FindClosestTriangleFast ( FPVector3  position,
NavMeshRegionMask  regionMask 
)
inline

Searches the closest triangle to the input position by using the fallback triangle saved for each grid cell. Result is quite inaccurate.

Parameters
positionInput position
regionMaskTriangle regions are checked if they are active
Returns
true if a triangle was found

◆ FindRandomPointOnTriangle()

bool Quantum.NavMesh.FindRandomPointOnTriangle ( Int32  triangle,
RNGSession rngSession,
out FPVector3  result 
)
inline

Generates a random point on the triangle.

Parameters
triangleTriangle index. Use FindTriangle() to find the triangle at a position.
rngSessionRandom number generator usually f->RNG.
resultRandom position on the triangle or Zero if the triangle does not exists.

◆ FindRandomPointOnNavmesh()

bool Quantum.NavMesh.FindRandomPointOnNavmesh ( FPVector3  position,
FP  radius,
RNGSession rngSession,
NavMeshRegionMask  regionMask,
out FPVector3  result 
)
inline

Tries to find a random position on the navmesh using the input position and radius. This can fail when there is no navmesh in range.

Parameters
positionCenter of random position circle
radiusSearch a random position inside this radius
rngSessionThe randomization session
regionMaskThe region mask to check
resultThe resulting randomized position.
Returns
true if a position has been found.

Creates a randomized position first, then tries validate it by finding a triangle at the random position (FindClosestTriangle). If all fail, false is returned.

Processing this offline and saving a custom data structure will probably result in more reliable and appealing results.

◆ IsBorderActive()

bool Quantum.NavMesh.IsBorderActive ( int  borderIndex,
NavMeshRegionMask  regionMask 
)
inline

Test if the region of the border at index is enabled.

Parameters
borderIndexBorder index
regionMaskRegion mask
Returns
true if region that the border belongs to is active

◆ Contains()

Boolean Quantum.NavMesh.Contains ( FPVector3  position,
NavMeshRegionMask  regionMask,
bool  inclusive = false 
)
inline

Checks if the position is on a navmesh triangle. Does only check the 2D coordinates.

Parameters
positionPosition
regionMaskTriangle regions are checked if they are active
inclusiveSet to true if positions exactly on a triangle edge or border are considered to be inside (default is false)
Returns
true if the position is on the navmesh

◆ MovePositionIntoNavmesh() [1/2]

unsafe FPVector2 Quantum.NavMesh.MovePositionIntoNavmesh ( FrameBase  frame,
FPVector2  position,
FPVector2  newPosition,
FP  correction,
NavMeshRegionMask  regionMask 
)
inline

This performs a correction of the agent movement against the navmesh borders much like solving physics contacts. This works only in 2D for now. Used internally if NavMeshAgentConfig.ClampAgentToNavmesh is set.

Parameters
frameFrame
positionAgent current position
newPositionAgent future position
correctionThe amount of correction in percent (0..1)
regionMaskRegion mask to check for active borders
Returns
Corrected position

◆ MovePositionIntoNavmesh() [2/2]

unsafe FPVector2 Quantum.NavMesh.MovePositionIntoNavmesh ( FrameThreadSafe  frame,
FPVector2  position,
FPVector2  newPosition,
FP  correction,
NavMeshRegionMask  regionMask 
)
inline

This performs a correction of the agent movement against the navmesh borders much like solving physics contacts. This works only in 2D for now. Used internally if NavMeshAgentConfig.ClampAgentToNavmesh is set.

Parameters
frameFrame
positionAgent current position
newPositionAgent future position
correctionThe amount of correction in percent (0..1)
regionMaskRegion mask to check for active borders
Returns
Corrected position

◆ Serialize()

void Quantum.NavMesh.Serialize ( ByteStream  stream,
Boolean  write 
)
inline

Serializes internal data structures (Triangles, TrianglesGrid, Vertices, BorderGrid, TrianglesCenterGrid, Regions, Borders) from the byte stream. Called during .

Parameters
streamByte stream
writeWrite or read

Member Data Documentation

◆ Name

String Quantum.NavMesh.Name

Name of the navmesh. Access the navmesh by name through Map.NavMeshes.

◆ SerializeType

NavMeshSerializeType Quantum.NavMesh.SerializeType

How the NavMesh should be serialized.

◆ DataAsset

AssetRef<BinaryData> Quantum.NavMesh.DataAsset

Asset that contains the actual binary navmesh data.

◆ GridSizeX

Int32 Quantum.NavMesh.GridSizeX

The navmesh triangles are partitioned by simple 2D grid. This is the number of all cells on the x-axis. Derived from the map values during baking.

◆ GridSizeY

Int32 Quantum.NavMesh.GridSizeY

The number of all grid cells on the y-axis. Derived from the map values during baking.

◆ GridNodeSize

Int32 Quantum.NavMesh.GridNodeSize

The number of units one grid cell has in both dimensions. Minimum 2. Must be an even number. Derived from the map values during baking.

◆ WorldOffset

FPVector2 Quantum.NavMesh.WorldOffset

The center of the map is the origin. The world offset represents the lower left corner and is copied from Map during the navmesh baking.

WorldOffset.X = -(GridSizeX * GridNodeSize) / 2

◆ MinAgentRadius

FP Quantum.NavMesh.MinAgentRadius

The smallest agent radius that the navmesh was created for (to pass visually nicely around the corners).

◆ Triangles

NavMeshTriangle [] Quantum.NavMesh.Triangles

Navmesh triangles.

◆ TrianglesGrid

NavMeshTriangleNode [] Quantum.NavMesh.TrianglesGrid

Per grid cell data structure that holds all indices to triangles inside this cell.

◆ Vertices

NavMeshVertex [] Quantum.NavMesh.Vertices

Navmesh vertices referenced by triangles.

◆ BorderGrid

NavMeshBorderNode [] Quantum.NavMesh.BorderGrid

Per grid cell data structure that holds all indices to borders inside this cell.

◆ TrianglesCenterGrid

NavMeshTriangleCenterGridNode [] Quantum.NavMesh.TrianglesCenterGrid

Per grid cell data structure that holds one (multiple if regions are used) triangle that is somewhat closest to the grid center as a fallback triangle lookup.

◆ Borders

NavMeshBorder [] Quantum.NavMesh.Borders

Navmesh borders.

◆ BorderCount

Int32 Quantum.NavMesh.BorderCount => Borders?.Length ?? 0

Gets the number of borders.

◆ Links

NavMeshLink [] Quantum.NavMesh.Links

All extra triangle connections on the navmesh called links.

◆ BakeData

NavMeshBakeData Quantum.NavMesh.BakeData = new NavMeshBakeData()

The BakeData of this navmesh, only used when serialization type is NavMeshSerializeType.BakeDataOnly.