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 #ifndef RECASTSAMPLETILEMESH_H 20 #define RECASTSAMPLETILEMESH_H 21 22 #include "Sample.h" 23 #include "DetourNavMesh.h" 24 #include "Recast.h" 25 #include "ChunkyTriMesh.h" 26 27 class Sample_TileMesh : public Sample 28 { 29 protected: 30 bool m_keepInterResults; 31 bool m_buildAll; 32 float m_totalBuildTimeMs; 33 34 unsigned char* m_triareas; 35 rcHeightfield* m_solid; 36 rcCompactHeightfield* m_chf; 37 rcContourSet* m_cset; 38 rcPolyMesh* m_pmesh; 39 rcPolyMeshDetail* m_dmesh; 40 rcConfig m_cfg; 41 42 enum DrawMode 43 { 44 DRAWMODE_NAVMESH, 45 DRAWMODE_NAVMESH_TRANS, 46 DRAWMODE_NAVMESH_BVTREE, 47 DRAWMODE_NAVMESH_NODES, 48 DRAWMODE_NAVMESH_PORTALS, 49 DRAWMODE_NAVMESH_INVIS, 50 DRAWMODE_MESH, 51 DRAWMODE_VOXELS, 52 DRAWMODE_VOXELS_WALKABLE, 53 DRAWMODE_COMPACT, 54 DRAWMODE_COMPACT_DISTANCE, 55 DRAWMODE_COMPACT_REGIONS, 56 DRAWMODE_REGION_CONNECTIONS, 57 DRAWMODE_RAW_CONTOURS, 58 DRAWMODE_BOTH_CONTOURS, 59 DRAWMODE_CONTOURS, 60 DRAWMODE_POLYMESH, 61 DRAWMODE_POLYMESH_DETAIL, 62 MAX_DRAWMODE 63 }; 64 65 DrawMode m_drawMode; 66 67 int m_maxTiles; 68 int m_maxPolysPerTile; 69 float m_tileSize; 70 71 unsigned int m_tileCol; 72 float m_lastBuiltTileBmin[3]; 73 float m_lastBuiltTileBmax[3]; 74 float m_tileBuildTime; 75 float m_tileMemUsage; 76 int m_tileTriCount; 77 78 unsigned char* buildTileMesh(const int tx, const int ty, const float* bmin, const float* bmax, int& dataSize); 79 80 void cleanup(); 81 82 void saveAll(const char* path, const dtNavMesh* mesh); 83 dtNavMesh* loadAll(const char* path); 84 85 public: 86 Sample_TileMesh(); 87 virtual ~Sample_TileMesh(); 88 89 virtual void handleSettings(); 90 virtual void handleTools(); 91 virtual void handleDebugMode(); 92 virtual void handleRender(); 93 virtual void handleRenderOverlay(double* proj, double* model, int* view); 94 virtual void handleMeshChanged(class InputGeom* geom); 95 virtual bool handleBuild(); 96 virtual void collectSettings(struct BuildSettings& settings); 97 98 void getTilePos(const float* pos, int& tx, int& ty); 99 100 void buildTile(const float* pos); 101 void removeTile(const float* pos); 102 void buildAllTiles(); 103 void removeAllTiles(); 104 105 private: 106 // Explicitly disabled copy constructor and copy assignment operator. 107 Sample_TileMesh(const Sample_TileMesh&); 108 Sample_TileMesh& operator=(const Sample_TileMesh&); 109 }; 110 111 112 #endif // RECASTSAMPLETILEMESH_H 113