9
3

InputGeom.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 INPUTGEOM_H
  19. #define INPUTGEOM_H
  20. #include "ChunkyTriMesh.h"
  21. #include "MeshLoaderObj.h"
  22. static const int MAX_CONVEXVOL_PTS = 12;
  23. struct ConvexVolume
  24. {
  25. float verts[MAX_CONVEXVOL_PTS*3];
  26. float hmin, hmax;
  27. int nverts;
  28. int area;
  29. };
  30. struct BuildSettings
  31. {
  32. // Cell size in world units
  33. float cellSize;
  34. // Cell height in world units
  35. float cellHeight;
  36. // Agent height in world units
  37. float agentHeight;
  38. // Agent radius in world units
  39. float agentRadius;
  40. // Agent max climb in world units
  41. float agentMaxClimb;
  42. // Agent max slope in degrees
  43. float agentMaxSlope;
  44. // Region minimum size in voxels.
  45. // regionMinSize = sqrt(regionMinArea)
  46. float regionMinSize;
  47. // Region merge size in voxels.
  48. // regionMergeSize = sqrt(regionMergeArea)
  49. float regionMergeSize;
  50. // Edge max length in world units
  51. float edgeMaxLen;
  52. // Edge max error in voxels
  53. float edgeMaxError;
  54. float vertsPerPoly;
  55. // Detail sample distance in voxels
  56. float detailSampleDist;
  57. // Detail sample max error in voxel heights.
  58. float detailSampleMaxError;
  59. // Partition type, see SamplePartitionType
  60. int partitionType;
  61. // Bounds of the area to mesh
  62. float navMeshBMin[3];
  63. float navMeshBMax[3];
  64. // Size of the tiles in voxels
  65. float tileSize;
  66. };
  67. class InputGeom
  68. {
  69. rcChunkyTriMesh* m_chunkyMesh;
  70. rcMeshLoaderObj* m_mesh;
  71. float m_meshBMin[3], m_meshBMax[3];
  72. BuildSettings m_buildSettings;
  73. bool m_hasBuildSettings;
  74. /// @name Off-Mesh connections.
  75. ///@{
  76. static const int MAX_OFFMESH_CONNECTIONS = 256;
  77. float m_offMeshConVerts[MAX_OFFMESH_CONNECTIONS*3*2];
  78. float m_offMeshConRads[MAX_OFFMESH_CONNECTIONS];
  79. unsigned char m_offMeshConDirs[MAX_OFFMESH_CONNECTIONS];
  80. unsigned char m_offMeshConAreas[MAX_OFFMESH_CONNECTIONS];
  81. unsigned short m_offMeshConFlags[MAX_OFFMESH_CONNECTIONS];
  82. unsigned int m_offMeshConId[MAX_OFFMESH_CONNECTIONS];
  83. int m_offMeshConCount;
  84. ///@}
  85. /// @name Convex Volumes.
  86. ///@{
  87. static const int MAX_VOLUMES = 256;
  88. ConvexVolume m_volumes[MAX_VOLUMES];
  89. int m_volumeCount;
  90. ///@}
  91. bool loadMesh(class rcContext* ctx, const std::string& filepath);
  92. bool loadGeomSet(class rcContext* ctx, const std::string& filepath);
  93. public:
  94. InputGeom();
  95. ~InputGeom();
  96. bool load(class rcContext* ctx, const std::string& filepath);
  97. bool saveGeomSet(const BuildSettings* settings);
  98. /// Method to return static mesh data.
  99. const rcMeshLoaderObj* getMesh() const { return m_mesh; }
  100. const float* getMeshBoundsMin() const { return m_meshBMin; }
  101. const float* getMeshBoundsMax() const { return m_meshBMax; }
  102. const float* getNavMeshBoundsMin() const { return m_hasBuildSettings ? m_buildSettings.navMeshBMin : m_meshBMin; }
  103. const float* getNavMeshBoundsMax() const { return m_hasBuildSettings ? m_buildSettings.navMeshBMax : m_meshBMax; }
  104. const rcChunkyTriMesh* getChunkyMesh() const { return m_chunkyMesh; }
  105. const BuildSettings* getBuildSettings() const { return m_hasBuildSettings ? &m_buildSettings : 0; }
  106. bool raycastMesh(float* src, float* dst, float& tmin);
  107. /// @name Off-Mesh connections.
  108. ///@{
  109. int getOffMeshConnectionCount() const { return m_offMeshConCount; }
  110. const float* getOffMeshConnectionVerts() const { return m_offMeshConVerts; }
  111. const float* getOffMeshConnectionRads() const { return m_offMeshConRads; }
  112. const unsigned char* getOffMeshConnectionDirs() const { return m_offMeshConDirs; }
  113. const unsigned char* getOffMeshConnectionAreas() const { return m_offMeshConAreas; }
  114. const unsigned short* getOffMeshConnectionFlags() const { return m_offMeshConFlags; }
  115. const unsigned int* getOffMeshConnectionId() const { return m_offMeshConId; }
  116. void addOffMeshConnection(const float* spos, const float* epos, const float rad,
  117. unsigned char bidir, unsigned char area, unsigned short flags);
  118. void deleteOffMeshConnection(int i);
  119. void drawOffMeshConnections(struct duDebugDraw* dd, bool hilight = false);
  120. ///@}
  121. /// @name Box Volumes.
  122. ///@{
  123. int getConvexVolumeCount() const { return m_volumeCount; }
  124. const ConvexVolume* getConvexVolumes() const { return m_volumes; }
  125. void addConvexVolume(const float* verts, const int nverts,
  126. const float minh, const float maxh, unsigned char area);
  127. void deleteConvexVolume(int i);
  128. void drawConvexVolumes(struct duDebugDraw* dd, bool hilight = false);
  129. ///@}
  130. private:
  131. // Explicitly disabled copy constructor and copy assignment operator.
  132. InputGeom(const InputGeom&);
  133. InputGeom& operator=(const InputGeom&);
  134. };
  135. #endif // INPUTGEOM_H