1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
//-----------------------------------------------------------------------------
// Name: tilemesh.h
// Developer: Wolfire Games LLC
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
//
// Copyright 2022 Wolfire Games LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once
#include <Math/vec3.h>
#include <AI/navmeshparameters.h>
#include <AI/sample.h>
#include <AI/chunky_tri_mesh.h>
#include <Recast.h>
#include <DetourNavMesh.h>
#include <DetourCrowd.h>
using std::pair;
class TileMesh
{
protected:
bool m_keepInterResults;
bool m_buildAll;
float m_totalBuildTimeMs;
unsigned char* m_triareas;
rcHeightfield* m_solid;
rcCompactHeightfield* m_chf;
rcContourSet* m_cset;
rcPolyMesh* m_pmesh;
rcPolyMeshDetail* m_dmesh;
rcConfig m_cfg;
BuildContext* m_ctx;
class InputGeom* m_geom;
class dtNavMesh* m_navMesh;
class dtNavMeshQuery* m_navQuery;
class dtCrowd* m_crowd;
unsigned char m_navMeshDrawFlags;
float m_cellSize;
float m_cellHeight;
float m_agentHeight;
float m_agentRadius;
float m_agentMaxClimb;
float m_agentMaxSlope;
float m_regionMinSize;
float m_regionMergeSize;
bool m_monotonePartitioning;
float m_edgeMaxLen;
float m_edgeMaxError;
float m_vertsPerPoly;
float m_detailSampleDist;
float m_detailSampleMaxError;
int m_maxTiles;
int m_maxPolysPerTile;
float m_tileSize;
unsigned int m_tileCol;
float m_tileBmin[3];
float m_tileBmax[3];
float m_tileBuildTime;
float m_tileMemUsage;
int m_tileTriCount;
bool m_use_explicit_bounderies;
vec3 m_Bmin;
vec3 m_Bmax;
unsigned char* buildTileMesh(const int tx, const int ty, const float* bmin, const float* bmax, int& dataSize);
void cleanup();
void saveAll(const char* path, const dtNavMesh* mesh);
dtNavMesh* loadAll(const char* path);
dtNavMesh* loadAllMem(const char* data, size_t size);
public:
TileMesh();
virtual ~TileMesh();
bool handleBuild();
void getTilePos(const float* pos, int& tx, int& ty);
void buildTile(const float* pos);
void removeTile(const float* pos);
void buildAllTiles();
void removeAllTiles();
void Save(const char *path);
void Load(const char *path);
void LoadMem(const char* data, size_t size);
const rcPolyMesh* getPolyMesh() const;
class dtNavMeshQuery* getNavMeshQuery() { return m_navQuery; }
void resetCommonSettings();
void applySettings(NavMeshParameters& nmp);
void setContext(BuildContext* ctx) { m_ctx = ctx; }
void handleMeshChanged(class InputGeom* geom);
void SetExplicitBounderies(vec3 min, vec3 max );
void RemoveExplicitBounderies();
pair<vec3,vec3> GetBoundaries();
const dtNavMesh* getNavMesh() const;
void handleSettings();
void handleCommonSettings();
};
|