Kemena3D
Loading...
Searching...
No Matches
knavmesh.h
Go to the documentation of this file.
1
5
6#ifndef KNAVMESH_H
7#define KNAVMESH_H
8
9#include "kexport.h"
10#include "kdatatype.h"
11
12#include <vector>
13
14namespace kemena
15{
16 // -------------------------------------------------------------------------
17 // Partition algorithm used during Recast region building
18 // -------------------------------------------------------------------------
19
32
33 // -------------------------------------------------------------------------
34 // Build configuration
35 // -------------------------------------------------------------------------
36
44 {
45 // Voxel grid
46 float cellSize = 0.3f;
47 float cellHeight = 0.2f;
48
49 // Agent dimensions
50 float agentHeight = 2.0f;
51 float agentRadius = 0.6f;
52 float agentMaxClimb = 0.9f;
53 float agentMaxSlope = 45.0f;
54
55 // Region merging
56 float regionMinSize = 8.0f;
57 float regionMergeSize = 20.0f;
58
59 // Edge simplification
60 float edgeMaxLen = 12.0f;
61 float edgeMaxError = 1.3f;
63
64 // Detail mesh
65 float detailSampleDist = 6.0f;
66 float detailSampleMaxError = 1.0f;
67
69
74 float tileSize = 48.0f;
75 };
76
77 // -------------------------------------------------------------------------
78 // Off-mesh connection (navmesh link)
79 // -------------------------------------------------------------------------
80
87 struct kNavLink
88 {
91 float radius = 0.6f;
92 bool bidirectional = true;
93 };
94
95 // -------------------------------------------------------------------------
96 // Editor-authored navigation surface descriptor
97 // -------------------------------------------------------------------------
98
108 {
110 bool useArea = false;
111 kVec3 areaSize = kVec3(20.0f, 10.0f, 20.0f);
112 };
113
114 // -------------------------------------------------------------------------
115 // kNavMesh
116 // -------------------------------------------------------------------------
117
140 {
141 public:
146
147 // --- Baking ----------------------------------------------------------
148
157 bool bake(const std::vector<float> &verts,
158 const std::vector<int> &tris,
159 const kNavBuildConfig &config = {},
160 const std::vector<kNavLink> &links = {});
161
163 void clear();
164
166 bool isBaked() const;
167
168 // --- Pathfinding -----------------------------------------------------
169
175 std::vector<kVec3> findPath(const kVec3 &start, const kVec3 &end,
176 int maxPoints = 256) const;
177
184 const kVec3 &extents = kVec3(2.f, 4.f, 2.f)) const;
185
187 bool isPointOnMesh(const kVec3 &pos,
188 const kVec3 &extents = kVec3(2.f, 4.f, 2.f)) const;
189
196 void getDebugLines(std::vector<kVec3> &outSegments) const;
197
198 // --- Internal (used by kNavManager) ----------------------------------
199
201 void *getNavMesh() const;
203 void *getNavMeshQuery() const;
205 void *getTileCache() const;
206
207 struct Impl;
208
209 protected:
210 private:
211 Impl *m_impl;
212 };
213
214} // namespace kemena
215
216#endif // KNAVMESH_H
void * getTileCache() const
Returns the internal dtTileCache pointer (null for non-tiled builds).
void * getNavMesh() const
Returns the internal dtNavMesh pointer (opaque).
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.
~kNavMesh()
Destroys the navmesh and releases all baked Recast/Detour data.
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.
void getDebugLines(std::vector< kVec3 > &outSegments) const
Extracts the navmesh surface as world-space line segments for debug visualisation (wireframe).
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 isBaked() const
Returns true if the mesh has been successfully baked.
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 * getNavMeshQuery() const
Returns the internal dtNavMeshQuery pointer (opaque).
void clear()
Destroys the baked data and resets to an unbaked state.
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Symbol visibility / linkage macro for the Kemena3D library.
#define KEMENA3D_API
Definition kexport.h:35
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33
kNavPartitionType
Partition algorithm used during Recast region building.
Definition knavmesh.h:27
@ Watershed
Best quality; slower on complex geometry.
Definition knavmesh.h:28
@ Monotone
Fast; lower quality on open areas.
Definition knavmesh.h:29
@ Layers
Best for very flat/layered geometry.
Definition knavmesh.h:30
All parameters that control the Recast bake pipeline.
Definition knavmesh.h:44
float detailSampleDist
Detail mesh sample spacing (cells); 0 disables detail sampling.
Definition knavmesh.h:65
float tileSize
Definition knavmesh.h:74
kNavPartitionType partition
Region partition algorithm.
Definition knavmesh.h:68
float regionMergeSize
Merge regions smaller than this (cells²).
Definition knavmesh.h:57
float cellSize
XZ voxel size (m). Smaller = finer mesh.
Definition knavmesh.h:46
float agentRadius
Agent cylinder radius (m).
Definition knavmesh.h:51
float detailSampleMaxError
Maximum detail mesh deviation from heightfield (cells).
Definition knavmesh.h:66
float edgeMaxError
Maximum edge deviation from original (m).
Definition knavmesh.h:61
float edgeMaxLen
Maximum edge length (m).
Definition knavmesh.h:60
float agentMaxClimb
Maximum step-up height (m).
Definition knavmesh.h:52
float regionMinSize
Discard regions smaller than this (cells²).
Definition knavmesh.h:56
int maxVertsPerPoly
Maximum vertices per navmesh polygon (2–6).
Definition knavmesh.h:62
float agentHeight
Minimum clear headroom (m).
Definition knavmesh.h:50
float agentMaxSlope
Maximum walkable slope (degrees).
Definition knavmesh.h:53
float cellHeight
Y voxel size (m).
Definition knavmesh.h:47
Serialisable settings for a navigation surface attached to an object in the editor.
Definition knavmesh.h:108
kNavBuildConfig config
Recast bake parameters.
Definition knavmesh.h:109
bool useArea
true = restrict to areaSize box.
Definition knavmesh.h:110
kVec3 areaSize
Full extents of the area box.
Definition knavmesh.h:111