NavigationMesh.pkg 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. $#include "NavigationMesh.h"
  2. /// Description of a navigation mesh geometry component, with transform and bounds information.
  3. struct NavigationGeometryInfo
  4. {
  5. /// Component.
  6. Component* component_;
  7. /// Geometry LOD level if applicable.
  8. unsigned lodLevel_;
  9. /// Transform relative to the navigation mesh root node.
  10. Matrix3x4 transform_;
  11. /// Bounding box relative to the navigation mesh root node.
  12. BoundingBox boundingBox_;
  13. };
  14. /// Navigation mesh component. Collects the navigation geometry from child nodes with the Navigable component and responds to path queries.
  15. class NavigationMesh : public Component
  16. {
  17. public:
  18. /// Set tile size.
  19. void SetTileSize(int size);
  20. /// Set cell size.
  21. void SetCellSize(float size);
  22. /// Set cell height.
  23. void SetCellHeight(float height);
  24. /// Set navigation agent height.
  25. void SetAgentHeight(float height);
  26. /// Set navigation agent radius.
  27. void SetAgentRadius(float radius);
  28. /// Set navigation agent max vertical climb.
  29. void SetAgentMaxClimb(float maxClimb);
  30. /// Set navigation agent max slope.
  31. void SetAgentMaxSlope(float maxSlope);
  32. /// Set region minimum size.
  33. void SetRegionMinSize(float size);
  34. /// Set region merge size.
  35. void SetRegionMergeSize(float size);
  36. /// Set edge max length.
  37. void SetEdgeMaxLength(float length);
  38. /// Set edge max error.
  39. void SetEdgeMaxError(float error);
  40. /// Set detail sampling distance.
  41. void SetDetailSampleDistance(float distance);
  42. /// Set detail sampling maximum error.
  43. void SetDetailSampleMaxError(float error);
  44. /// Set padding of the navigation mesh bounding box. Having enough padding allows to add geometry on the extremities of the navigation mesh when doing partial rebuilds.
  45. void SetPadding(const Vector3& padding);
  46. /// Rebuild the navigation mesh. Return true if successful.
  47. bool Build();
  48. /// Rebuild part of the navigation mesh contained by the world-space bounding box. Return true if successful.
  49. bool Build(const BoundingBox& boundingBox);
  50. /// Find a path between world space points. Return non-empty list of points if successful. Extents specifies how far off the navigation mesh the points can be.
  51. tolua_outside PODVector<Vector3> NavigationMeshFindPath @ FindPath(const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE);
  52. tolua_outside PODVector<Vector3> NavigationMeshFindPath @ FindPath(const Vector3& start, const Vector3& end);
  53. /// Return a random point on the navigation mesh.
  54. Vector3 GetRandomPoint();
  55. /// Return a random point on the navigation mesh within a circle. The circle radius is only a guideline and in practice the returned point may be further away.
  56. Vector3 GetRandomPointInCircle(const Vector3& center, float radius, const Vector3& extents = Vector3::ONE);
  57. /// Return distance to wall from a point. Maximum search radius must be specified.
  58. float GetDistanceToWall(const Vector3& point, float radius, const Vector3& extents = Vector3::ONE);
  59. /// Perform a walkability raycast on the navigation mesh between start and end and return the point where a wall was hit, or the end point if no walls.
  60. Vector3 Raycast(const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE);
  61. /// Return tile size.
  62. int GetTileSize() const { return tileSize_; }
  63. /// Return cell size.
  64. float GetCellSize() const { return cellSize_; }
  65. /// Return cell height.
  66. float GetCellHeight() const { return cellHeight_; }
  67. /// Return navigation agent height.
  68. float GetAgentHeight() const { return agentHeight_; }
  69. /// Return navigation agent radius.
  70. float GetAgentRadius() const { return agentRadius_; }
  71. /// Return navigation agent max vertical climb.
  72. float GetAgentMaxClimb() const { return agentMaxClimb_; }
  73. /// Return navigation agent max slope.
  74. float GetAgentMaxSlope() const { return agentMaxSlope_; }
  75. /// Return region minimum size.
  76. float GetRegionMinSize() const { return regionMinSize_; }
  77. /// Return region merge size.
  78. float GetRegionMergeSize() const { return regionMergeSize_; }
  79. /// Return edge max length.
  80. float GetEdgeMaxLength() const { return edgeMaxLength_; }
  81. /// Return edge max error.
  82. float GetEdgeMaxError() const { return edgeMaxError_; }
  83. /// Return detail sampling distance.
  84. float GetDetailSampleDistance() const { return detailSampleDistance_; }
  85. /// Return detail sampling maximum error.
  86. float GetDetailSampleMaxError() const { return detailSampleMaxError_; }
  87. /// Return navigation mesh bounding box padding.
  88. const Vector3& GetPadding() const { return padding_; }
  89. /// Return whether has been initialized with valid navigation data.
  90. bool IsInitialized() const { return navMesh_ != 0; }
  91. /// Return local space bounding box of the navigation mesh.
  92. const BoundingBox& GetBoundingBox() const { return boundingBox_; }
  93. /// Return world space bounding box of the navigation mesh.
  94. BoundingBox GetWorldBoundingBox() const;
  95. /// Return number of tiles.
  96. IntVector2 GetNumTiles() const { return IntVector2(numTilesX_, numTilesZ_); }
  97. // Properties:
  98. tolua_property__get_set int tileSize;
  99. tolua_property__get_set float cellSize;
  100. tolua_property__get_set float cellHeight;
  101. tolua_property__get_set float agentHeight;
  102. tolua_property__get_set float agentRadius;
  103. tolua_property__get_set float agentMaxClimb;
  104. tolua_property__get_set float agentMaxSlope;
  105. tolua_property__get_set float regionMinSize;
  106. tolua_property__get_set float regionMergeSize;
  107. tolua_property__get_set float edgeMaxLength;
  108. tolua_property__get_set float edgeMaxError;
  109. tolua_property__get_set float detailSampleDistance;
  110. tolua_property__get_set float detailSampleMaxError;
  111. tolua_property__get_set const Vector3& padding;
  112. tolua_readonly tolua_property__is_set bool initialized;
  113. tolua_readonly tolua_property__get_set const BoundingBox& boundingBox;
  114. tolua_readonly tolua_property__get_set BoundingBox worldBoundingBox;
  115. tolua_readonly tolua_property__get_set IntVector2 numTiles;
  116. };
  117. ${
  118. PODVector<Vector3> NavigationMeshFindPath(NavigationMesh* navMesh, const Vector3& start, const Vector3& end, const Vector3& extents = Vector3::ONE)
  119. {
  120. PODVector<Vector3> dest;
  121. navMesh->FindPath(dest, start, end, extents);
  122. return dest;
  123. }
  124. $}