Nebula
Loading...
Searching...
No Matches
navmeshbuilder.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
32//------------------------------------------------------------------------------
33#include "util/array.h"
34#include "util/blob.h"
35#include "math/mat4.h"
36#include "math/bbox.h"
37#include "math/vec3.h"
38#include "flat/navigation/navmeshsettings.h"
39#include "flat/navigation/agentkinds.h"
40#include "DetourNavMesh.h"
41
42namespace Navigation
43{
44namespace Build
45{
46
48static constexpr unsigned char DefaultWalkableArea = 63;
49
51enum PolyFlags : unsigned short
52{
53 PolyFlag_Walk = 1 << 0,
54};
55
58{
59 Util::Array<float> positions; // 3 floats per vertex, in the space of the source
60 Util::Array<uint> indices; // triangle list, counter clockwise seen from the walkable side
61 Math::mat4 transform; // source to world
62};
63
66{
67 SizeT width = 0; // samples along x
68 SizeT height = 0; // samples along z
69 Util::Array<ushort> samples; // samples[z * width + x], 0 is the bottom and 65535 the top of the height range
70 float heightRange = 1.0f; // vertical span in meters
71 float sizeX = 1.0f; // world extent along x
72 float sizeZ = 1.0f; // world extent along z
73 Math::mat4 transform; // field to world, the origin is the corner of the field
74};
75
78{
79 enum Shape
80 {
81 ConvexPrism, // points, between minY and maxY
82 Cylinder // center and radius, between minY and maxY
83 };
85 Util::Array<Math::vec3> points; // convex outline in world space, only x and z are used
86 Math::vec3 center; // cylinder axis, only x and z are used
87 float radius = 0.0f;
88 float minY = 0.0f;
89 float maxY = 0.0f;
90 unsigned char area = 0; // Recast area, 0 cuts the surface out
91 int priority = 0; // volumes are applied from low to high priority
92};
93
96{
97 Navigation::NavMeshSettingsT settings;
98 Navigation::AgentT agent;
100 bool useSourceBounds = true;
107 unsigned short areaFlags[64];
108
110 {
111 // every area is walkable unless an area table says otherwise
112 for (int i = 0; i < 64; i++)
113 {
114 this->areaFlags[i] = i == 0 ? 0 : PolyFlag_Walk;
115 }
116 }
117};
118
120struct Tile
121{
122 int x = 0;
123 int y = 0;
124 int layer = 0;
126};
127
130{
131 dtNavMeshParams params;
133};
134
137{
138 int tilesX = 0;
139 int tilesZ = 0;
140 int builtTiles = 0; // tiles with walkable surface
141 int failedTiles = 0; // tiles which hit a Recast or Detour limit
142 int inputTriangles = 0; // mesh and height field triangles which were rasterized, counted once per tile
143 int polygons = 0;
144};
145
149bool BuildNavMesh(const BuildInput& input, BuildOutput& output, BuildStats* stats = nullptr);
151dtNavMesh* CreateDetourNavMesh(const BuildOutput& output);
152
153} // namespace Build
154} // namespace Navigation
Nebula's bounding box class.
Definition bbox.h:24
Nebula's dynamic array class.
Definition array.h:61
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
Definition geometrysources.cc:15
PolyFlags
polygon flags written into the Detour data
Definition navmeshbuilder.h:52
@ PolyFlag_Walk
Definition navmeshbuilder.h:53
Math::bbox SourceBounds(const BuildInput &input)
return the world bounds of all sources
Definition navmeshbuilder.cc:143
bool BuildNavMesh(const BuildInput &input, BuildOutput &output, BuildStats *outStats)
build the navmesh, returns false if nothing walkable was found or a tile failed
Definition navmeshbuilder.cc:589
dtNavMesh * CreateDetourNavMesh(const BakedNavMesh *baked)
create a Detour navmesh from baked data, the tile data is copied. Free with dtFreeNavMesh
Definition navmeshasset.cc:372
static constexpr unsigned char DefaultWalkableArea
the area of walkable surface which no area volume covers, Recast's RC_WALKABLE_AREA
Definition navmeshbuilder.h:48
Navigation::Build geometry sources.
Definition geometrysources.cc:13
A 4x4 single point precision float matrix.
Definition mat4.h:55
A 3D vector.
Definition vec3.h:37
assigns an area to the walkable surface inside it
Definition navmeshbuilder.h:78
Shape
Definition navmeshbuilder.h:80
@ ConvexPrism
Definition navmeshbuilder.h:81
@ Cylinder
Definition navmeshbuilder.h:82
Shape shape
Definition navmeshbuilder.h:84
float minY
Definition navmeshbuilder.h:88
unsigned char area
Definition navmeshbuilder.h:90
float maxY
Definition navmeshbuilder.h:89
Math::vec3 center
Definition navmeshbuilder.h:86
int priority
Definition navmeshbuilder.h:91
float radius
Definition navmeshbuilder.h:87
Util::Array< Math::vec3 > points
Definition navmeshbuilder.h:85
everything a build needs
Definition navmeshbuilder.h:96
BuildInput()
Definition navmeshbuilder.h:109
Navigation::AgentT agent
Definition navmeshbuilder.h:98
Util::Array< MeshSource > meshes
Definition navmeshbuilder.h:103
Navigation::NavMeshSettingsT settings
Definition navmeshbuilder.h:97
bool useSourceBounds
build in the bounds of all sources, padded by the agent height, instead of bounds
Definition navmeshbuilder.h:100
Util::Array< AreaVolume > areas
Definition navmeshbuilder.h:105
Math::bbox bounds
the world space volume the navmesh is built in
Definition navmeshbuilder.h:102
Util::Array< HeightFieldSource > heightFields
Definition navmeshbuilder.h:104
unsigned short areaFlags[64]
Detour polygon flags of every area id.
Definition navmeshbuilder.h:107
the built navmesh
Definition navmeshbuilder.h:130
dtNavMeshParams params
Definition navmeshbuilder.h:131
Util::Array< Tile > tiles
Definition navmeshbuilder.h:132
statistics of a build
Definition navmeshbuilder.h:137
int polygons
Definition navmeshbuilder.h:143
int inputTriangles
Definition navmeshbuilder.h:142
int tilesZ
Definition navmeshbuilder.h:139
int tilesX
Definition navmeshbuilder.h:138
int failedTiles
Definition navmeshbuilder.h:141
int builtTiles
Definition navmeshbuilder.h:140
height field placed in the world, laid out like Physics::HeightFieldInput
Definition navmeshbuilder.h:66
Util::Array< ushort > samples
Definition navmeshbuilder.h:69
float sizeX
Definition navmeshbuilder.h:71
float sizeZ
Definition navmeshbuilder.h:72
Math::mat4 transform
Definition navmeshbuilder.h:73
SizeT height
Definition navmeshbuilder.h:68
float heightRange
Definition navmeshbuilder.h:70
SizeT width
Definition navmeshbuilder.h:67
triangle geometry placed in the world
Definition navmeshbuilder.h:58
Util::Array< uint > indices
Definition navmeshbuilder.h:60
Util::Array< float > positions
Definition navmeshbuilder.h:59
Math::mat4 transform
Definition navmeshbuilder.h:61
one tile of Detour data, as dtCreateNavMeshData produced it
Definition navmeshbuilder.h:121
int layer
Definition navmeshbuilder.h:124
int y
Definition navmeshbuilder.h:123
Util::Blob data
Definition navmeshbuilder.h:125
int x
Definition navmeshbuilder.h:122
int SizeT
Definition types.h:50