forked from tizbac/NavMeshViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapBuilder.h
140 lines (110 loc) · 5.08 KB
/
MapBuilder.h
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
132
133
134
135
136
137
138
139
140
#ifndef _MAP_BUILDER_2_H
#define _MAP_BUILDER_2_H
#include <vector>
#include <set>
#include <map>
#include "TileBuilder.h"
#include "IVMapManager.h"
#include "G3D/Array.h"
#include "ChunkyTriMesh.h"
#include "Recast.h"
#include "DetourNavMesh.h"
using namespace std;
using namespace VMAP;
// G3D namespace typedefs conflicts with ACE typedefs
namespace MMAP
{
typedef set<uint32> MapList;
typedef map<uint32,set<uint32>*> TileList;
struct IntermediateValues
{
rcHeightfield* heightfield;
unsigned char* triFlags;
rcCompactHeightfield* compactHeightfield;
rcContourSet* contours;
rcPolyMesh* polyMesh;
rcPolyMeshDetail* polyMeshDetail;
};
class MapBuilder
{
public:
MapBuilder(float maxWalkableAngle = 60.f,
bool skipContinents = true,
bool skipJunkMaps = true,
bool skipBattlegrounds = true,
bool hiResHeightmaps = false,
bool debugOutput = false);
~MapBuilder();
/**
Builds a mmap for the specifiec map id.
* First, the entire vmap is loaded. Cannot do it tile-by-tile because vmap tiles only load models
whose origin is in that tile. Large models may span across tiles (stormwind, etc)
* Second, iterates through the tiles and loads their heightmaps.
These are processed so that steep inclines are removed.
TODO: process liquid heightmap
* Third, the vmap model and heightmap data is aggregated
* Fourth, data is sent off to recast for processing. This optionally includes generating
an obj file, for debugging with RecastDemo
*/
void build(uint32 mapID);
// generates an obj file for the specified map tile
void buildTile(uint32 mapID, uint32 tileX, uint32 tileY);
// builds list of maps, then iterates through them calling build(uint32 mapID)
void buildAll();
private:
// detect maps and tiles
void getTileList(uint32 mapID);
void getMapList();
// load and unload models
void loadEntireVMap(uint32 mapID);
void loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, G3D::Array<float> &modelVerts, G3D::Array<int> &modelTris);
void unloadEntireVMap(uint32 mapID);
void unloadVMap(uint32 mapID, uint32 tileX, uint32 tileY);
// vert and triangle methods
void transform(vector<Vector3> original, vector<Vector3> &transformed,
float scale, G3D::Matrix3 rotation, Vector3 position);
void copyVertices(vector<Vector3> source, G3D::Array<float> &dest);
void copyIndices(vector<MeshTriangle> source, G3D::Array<int> &dest, int offest, bool flip);
void copyIndices(G3D::Array<int> &dest, G3D::Array<int> src, int offset);
void cleanVertices(G3D::Array<float> &verts, G3D::Array<int> &tris);
void cleanup();
// move map building
void buildMoveMap(uint32 mapID);
void buildNavMesh(uint32 mapID, dtNavMesh* &navMesh);
void buildMoveMapTile(uint32 mapID,
uint32 tileX,
uint32 tileY,
MeshData meshData,
float* bmin,
float* bmax,
dtNavMesh* navMesh);
void getTileBounds(uint32 tileX, uint32 tileY,
float* verts, int vertCount,
float* bmin, float* bmax);
void initIntermediateValues(IntermediateValues &iv);
void clearIntermediateValues(IntermediateValues &iv);
float snapToGrid(const float coord);
bool shouldSkipMap(uint32 mapID);
bool isTransportMap(uint32 mapID);
// debug output
void generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData meshData);
void writeIV(uint32 mapID, uint32 tileX, uint32 tileY, IntermediateValues iv);
void writeHeightfield(FILE* file, const rcHeightfield* hf);
void writeSpan(FILE* file, const rcSpan* span);
void writeCompactHeightfield(FILE* file, const rcCompactHeightfield* chf);
void writeContours(FILE* file, const rcContourSet* cs);
void writeChunkyTriMesh(FILE* file, const rcChunkyTriMesh* mesh);
void writePolyMesh(FILE* file, const rcPolyMesh* mesh);
void writeDetailMesh(FILE* file, const rcPolyMeshDetail* mesh);
IVMapManager* m_vmapManager;
TileBuilder* m_tileBuilder;
MapList m_maps;
TileList m_tiles;
bool m_debugOutput;
bool m_skipContinents;
bool m_skipJunkMaps;
bool m_skipBattlegrounds;
float m_maxWalkableAngle;
};
}
#endif