Sample_TileMesh.h 3.1 KB

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