Kemena3D
Loading...
Searching...
No Matches
kemena::kNavMesh Class Reference

A baked navigation mesh used for pathfinding and obstacle simulation. More...

#include <knavmesh.h>

Public Member Functions

 kNavMesh ()
 Constructs an empty, unbaked navigation mesh.
 ~kNavMesh ()
 Destroys the navmesh and releases all baked Recast/Detour data.
bool bake (const std::vector< float > &verts, const std::vector< int > &tris, const kNavBuildConfig &config={}, const std::vector< kNavLink > &links={})
 Builds the navigation mesh from raw triangle geometry.
void clear ()
 Destroys the baked data and resets to an unbaked state.
bool isBaked () const
 Returns true if the mesh has been successfully baked.
std::vector< kVec3findPath (const kVec3 &start, const kVec3 &end, int maxPoints=256) const
 Finds a smoothed path along the navmesh from start to end.
kVec3 findNearestPoint (const kVec3 &pos, const kVec3 &extents=kVec3(2.f, 4.f, 2.f)) const
 Finds the nearest point on the navmesh surface to pos.
bool isPointOnMesh (const kVec3 &pos, const kVec3 &extents=kVec3(2.f, 4.f, 2.f)) const
 Returns true if pos is on (or very near) the navmesh.
void getDebugLines (std::vector< kVec3 > &outSegments) const
 Extracts the navmesh surface as world-space line segments for debug visualisation (wireframe).
void * getNavMesh () const
 Returns the internal dtNavMesh pointer (opaque).
void * getNavMeshQuery () const
 Returns the internal dtNavMeshQuery pointer (opaque).
void * getTileCache () const
 Returns the internal dtTileCache pointer (null for non-tiled builds).

Detailed Description

A baked navigation mesh used for pathfinding and obstacle simulation.

Create one kNavMesh per scene. Call bake() with your world geometry, then pass the mesh to kNavManager::init() to drive agents and obstacles.

kNavMesh* nav = new kNavMesh();
// Collect world geometry
std::vector<float> verts; // x,y,z,x,y,z,...
std::vector<int> tris; // i0,i1,i2,...
// ... fill from your world mesh ...
cfg.agentRadius = 0.4f;
nav->bake(verts, tris, cfg);
auto path = nav->findPath(start, end);
kNavMesh()
Constructs an empty, unbaked navigation mesh.
std::vector< kVec3 > findPath(const kVec3 &start, const kVec3 &end, int maxPoints=256) const
Finds a smoothed path along the navmesh from start to end.
bool bake(const std::vector< float > &verts, const std::vector< int > &tris, const kNavBuildConfig &config={}, const std::vector< kNavLink > &links={})
Builds the navigation mesh from raw triangle geometry.
All parameters that control the Recast bake pipeline.
Definition knavmesh.h:44
float agentRadius
Agent cylinder radius (m).
Definition knavmesh.h:51

Constructor & Destructor Documentation

◆ kNavMesh()

kemena::kNavMesh::kNavMesh ( )

Constructs an empty, unbaked navigation mesh.

◆ ~kNavMesh()

kemena::kNavMesh::~kNavMesh ( )

Destroys the navmesh and releases all baked Recast/Detour data.

Member Function Documentation

◆ bake()

bool kemena::kNavMesh::bake ( const std::vector< float > & verts,
const std::vector< int > & tris,
const kNavBuildConfig & config = {},
const std::vector< kNavLink > & links = {} )

Builds the navigation mesh from raw triangle geometry.

Parameters
vertsFlat vertex buffer: x0,y0,z0, x1,y1,z1, ...
trisFlat index buffer: i0,i1,i2, i3,i4,i5, ...
configVoxelisation and agent parameters.
linksOptional off-mesh connections (ladders, jumps, …).
Returns
true on success.

◆ clear()

void kemena::kNavMesh::clear ( )

Destroys the baked data and resets to an unbaked state.

◆ findNearestPoint()

kVec3 kemena::kNavMesh::findNearestPoint ( const kVec3 & pos,
const kVec3 & extents = kVec3(2.f, 4.f, 2.f) ) const

Finds the nearest point on the navmesh surface to pos.

Parameters
extentsHalf-extents of the AABB search region.
Returns
Snapped position, or pos unchanged if nothing is found.

◆ findPath()

std::vector< kVec3 > kemena::kNavMesh::findPath ( const kVec3 & start,
const kVec3 & end,
int maxPoints = 256 ) const

Finds a smoothed path along the navmesh from start to end.

Parameters
maxPointsMaximum number of waypoints in the returned path.
Returns
World-space waypoints from start to end. Empty if unreachable.

◆ getDebugLines()

void kemena::kNavMesh::getDebugLines ( std::vector< kVec3 > & outSegments) const

Extracts the navmesh surface as world-space line segments for debug visualisation (wireframe).

Parameters
outSegmentsFilled with pairs of points; each consecutive pair (0,1), (2,3), … is one line. Cleared first.

◆ getNavMesh()

void * kemena::kNavMesh::getNavMesh ( ) const

Returns the internal dtNavMesh pointer (opaque).

◆ getNavMeshQuery()

void * kemena::kNavMesh::getNavMeshQuery ( ) const

Returns the internal dtNavMeshQuery pointer (opaque).

◆ getTileCache()

void * kemena::kNavMesh::getTileCache ( ) const

Returns the internal dtTileCache pointer (null for non-tiled builds).

◆ isBaked()

bool kemena::kNavMesh::isBaked ( ) const

Returns true if the mesh has been successfully baked.

◆ isPointOnMesh()

bool kemena::kNavMesh::isPointOnMesh ( const kVec3 & pos,
const kVec3 & extents = kVec3(2.f, 4.f, 2.f) ) const

Returns true if pos is on (or very near) the navmesh.


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