Recast Navigation
Navigation-mesh Toolset for Games
Loading...
Searching...
No Matches
InputGeom.h
Go to the documentation of this file.
1//
2// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3//
4// This software is provided 'as-is', without any express or implied
5// warranty. In no event will the authors be held liable for any damages
6// arising from the use of this software.
7// Permission is granted to anyone to use this software for any purpose,
8// including commercial applications, and to alter it and redistribute it
9// freely, subject to the following restrictions:
10// 1. The origin of this software must not be misrepresented; you must not
11// claim that you wrote the original software. If you use this software
12// in a product, an acknowledgment in the product documentation would be
13// appreciated but is not required.
14// 2. Altered source versions must be plainly marked as such, and must not be
15// misrepresented as being the original software.
16// 3. This notice may not be removed or altered from any source distribution.
17//
18
19#pragma once
20
21#include "PartitionedMesh.h"
22
23#include <string>
24#include <vector>
25
26struct PartitionedMesh;
27class rcContext;
28struct duDebugDraw;
29
30static constexpr int MAX_CONVEXVOL_PTS = 12;
32{
33 float verts[MAX_CONVEXVOL_PTS * 3] = {};
34 int nverts = 0;
35 float hmin = 0.0f;
36 float hmax = 0.0f;
37 int area = 0;
38};
39
41{
43 float cellSize = 0;
45 float cellHeight = 0;
47 float agentHeight = 0;
49 float agentRadius = 0;
51 float agentMaxClimb = 0;
53 float agentMaxSlope = 0;
55 float regionMinSize = 0;
57 float regionMergeSize = 0;
59 float edgeMaxLen = 0;
61 float edgeMaxError = 0;
62 int vertsPerPoly = 0;
70 float navMeshBMin[3]{};
71 float navMeshBMax[3]{};
73 float tileSize = 0;
74};
75
76struct Mesh
77{
78 std::vector<float> verts;
79 std::vector<int> tris;
80 std::vector<float> normals; // face normals
81
82 void reset()
83 {
84 verts.clear();
85 tris.clear();
86 normals.clear();
87 }
88
89 [[nodiscard]] int getVertCount() const { return static_cast<int>(verts.size()) / 3; }
90 [[nodiscard]] int getTriCount() const { return static_cast<int>(tris.size()) / 3; }
91
92 void readFromObj(char* buf, size_t bufLen);
93};
94
96{
97 BuildSettings buildSettings;
98 bool hasBuildSettings = false;
99
100public:
101 std::string filename;
102
104 float meshBoundsMin[3] = {};
105 float meshBoundsMax[3] = {};
106
108
111 std::vector<float> offmeshConnVerts;
112 std::vector<float> offmeshConnRadius;
113 std::vector<unsigned char> offmeshConnBidirectional;
114 std::vector<unsigned char> offmeshConnArea;
115 std::vector<unsigned short> offmeshConnFlags;
116 std::vector<unsigned int> offmeshConnId;
118
119 std::vector<ConvexVolume> convexVolumes;
120
121 bool load(rcContext* ctx, const std::string& filepath);
122 bool saveGeomSet(const BuildSettings* settings);
123
125 [[nodiscard]] const float* getNavMeshBoundsMin() const { return hasBuildSettings ? buildSettings.navMeshBMin : meshBoundsMin; }
126 [[nodiscard]] const float* getNavMeshBoundsMax() const { return hasBuildSettings ? buildSettings.navMeshBMax : meshBoundsMax; }
127 [[nodiscard]] const BuildSettings* getBuildSettings() const { return hasBuildSettings ? &buildSettings : nullptr; }
128 bool raycastMesh(float* src, float* dst, float& tmin) const;
129
132 void addOffMeshConnection(const float* startPos, const float* endPos, float radius, unsigned char bidirectional, unsigned char area, unsigned short flags);
133 void deleteOffMeshConnection(int i);
134 void drawOffMeshConnections(duDebugDraw* dd, bool highlight = false);
136
139 void addConvexVolume(const float* verts, int nverts, float minh, float maxh, unsigned char area);
140 void deleteConvexVolume(int i);
143
144private:
145 bool loadMesh(rcContext* ctx, const std::string& filepath);
146 bool loadGeomSet(rcContext* ctx, const std::string& filepath);
147 bool loadGeomSet(rcContext* ctx, char* buffer, size_t bufferLen);
148
149 void clearOffMeshConnections()
150 {
151 offmeshConnVerts.clear();
152 offmeshConnRadius.clear();
154 offmeshConnArea.clear();
155 offmeshConnFlags.clear();
156 offmeshConnId.clear();
157 }
158};
159
static constexpr int MAX_CONVEXVOL_PTS
Definition InputGeom.h:30
Definition InputGeom.h:96
std::vector< unsigned char > offmeshConnBidirectional
Definition InputGeom.h:113
void deleteConvexVolume(int i)
Definition InputGeom.cpp:730
float meshBoundsMax[3]
Definition InputGeom.h:105
bool load(rcContext *ctx, const std::string &filepath)
Definition InputGeom.cpp:496
Mesh mesh
Definition InputGeom.h:103
void addOffMeshConnection(const float *startPos, const float *endPos, float radius, unsigned char bidirectional, unsigned char area, unsigned short flags)
Definition InputGeom.cpp:649
const float * getNavMeshBoundsMax() const
Definition InputGeom.h:126
void drawOffMeshConnections(duDebugDraw *dd, bool highlight=false)
Definition InputGeom.cpp:678
std::string filename
Definition InputGeom.h:101
void addConvexVolume(const float *verts, int nverts, float minh, float maxh, unsigned char area)
Definition InputGeom.cpp:719
bool saveGeomSet(const BuildSettings *settings)
Definition InputGeom.cpp:519
const float * getNavMeshBoundsMin() const
Method to return static mesh data.
Definition InputGeom.h:125
std::vector< unsigned int > offmeshConnId
Definition InputGeom.h:116
std::vector< float > offmeshConnRadius
Definition InputGeom.h:112
std::vector< ConvexVolume > convexVolumes
Definition InputGeom.h:119
float meshBoundsMin[3]
Definition InputGeom.h:104
const BuildSettings * getBuildSettings() const
Definition InputGeom.h:127
void drawConvexVolumes(duDebugDraw *dd)
Definition InputGeom.cpp:735
PartitionedMesh partitionedMesh
Definition InputGeom.h:107
std::vector< unsigned short > offmeshConnFlags
Definition InputGeom.h:115
std::vector< float > offmeshConnVerts
Definition InputGeom.h:111
void deleteOffMeshConnection(int i)
Definition InputGeom.cpp:668
std::vector< unsigned char > offmeshConnArea
Definition InputGeom.h:114
bool raycastMesh(float *src, float *dst, float &tmin) const
Definition InputGeom.cpp:600
Provides an interface for optional logging and performance tracking of the Recast build process.
Definition Recast.h:115
Definition InputGeom.h:41
float agentHeight
Agent height in world units.
Definition InputGeom.h:47
float navMeshBMin[3]
Bounds of the area to mesh.
Definition InputGeom.h:70
int vertsPerPoly
Definition InputGeom.h:62
int partitionType
Partition type, see SamplePartitionType.
Definition InputGeom.h:68
float regionMinSize
Region minimum size in voxels.
Definition InputGeom.h:55
float agentMaxSlope
Agent max slope in degrees.
Definition InputGeom.h:53
float detailSampleMaxError
Detail sample max error in voxel heights.
Definition InputGeom.h:66
float agentMaxClimb
Agent max climb in world units.
Definition InputGeom.h:51
float edgeMaxError
Edge max error in voxels.
Definition InputGeom.h:61
float agentRadius
Agent radius in world units.
Definition InputGeom.h:49
float cellSize
Cell size in world units.
Definition InputGeom.h:43
float navMeshBMax[3]
Definition InputGeom.h:71
float tileSize
Size of the tiles in voxels.
Definition InputGeom.h:73
float detailSampleDist
Detail sample distance in voxels.
Definition InputGeom.h:64
float cellHeight
Cell height in world units.
Definition InputGeom.h:45
float edgeMaxLen
Edge max length in world units.
Definition InputGeom.h:59
float regionMergeSize
Region merge size in voxels. regionMergeSize = sqrt(regionMergeArea)
Definition InputGeom.h:57
Definition InputGeom.h:32
float hmax
Definition InputGeom.h:36
float hmin
Definition InputGeom.h:35
float verts[MAX_CONVEXVOL_PTS *3]
Definition InputGeom.h:33
int nverts
Definition InputGeom.h:34
int area
Definition InputGeom.h:37
Definition InputGeom.h:77
std::vector< float > verts
Definition InputGeom.h:78
int getVertCount() const
Definition InputGeom.h:89
std::vector< float > normals
Definition InputGeom.h:80
void reset()
Definition InputGeom.h:82
int getTriCount() const
Definition InputGeom.h:90
void readFromObj(char *buf, size_t bufLen)
Definition InputGeom.cpp:249
std::vector< int > tris
Definition InputGeom.h:79
A spatially-partitioned mesh (k/d tree), where each node contains at max trisPerChunk triangles.
Definition PartitionedMesh.h:26
Abstract debug draw interface.
Definition DebugDraw.h:35