NavigationMesh.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "CollisionShape.h"
  24. #include "Context.h"
  25. #include "Drawable.h"
  26. #include "Geometry.h"
  27. #include "Log.h"
  28. #include "Navigable.h"
  29. #include "NavigationMesh.h"
  30. #include "Profiler.h"
  31. #include "Scene.h"
  32. #include "StaticModel.h"
  33. #include "TerrainPatch.h"
  34. #include <DetourNavMesh.h>
  35. #include <DetourNavMeshBuilder.h>
  36. #include <Recast.h>
  37. #include "DebugNew.h"
  38. namespace Urho3D
  39. {
  40. static const float DEFAULT_CELL_SIZE = 0.3f;
  41. static const float DEFAULT_CELL_HEIGHT = 0.2f;
  42. static const float DEFAULT_AGENT_HEIGHT = 2.0f;
  43. static const float DEFAULT_AGENT_RADIUS = 0.6f;
  44. static const float DEFAULT_AGENT_MAX_CLIMB = 0.9f;
  45. static const float DEFAULT_AGENT_MAX_SLOPE = 45.0f;
  46. static const float DEFAULT_REGION_MIN_SIZE = 8.0f;
  47. static const float DEFAULT_REGION_MERGE_SIZE = 20.0f;
  48. static const float DEFAULT_EDGE_MAX_LENGTH = 12.0f;
  49. static const float DEFAULT_EDGE_MAX_ERROR = 1.3f;
  50. static const float DEFAULT_DETAIL_SAMPLE_DISTANCE = 6.0f;
  51. static const float DEFAULT_DETAIL_SAMPLE_MAX_ERROR = 1.0f;
  52. OBJECTTYPESTATIC(NavigationMesh);
  53. NavigationMesh::NavigationMesh(Context* context) :
  54. Component(context),
  55. cellSize_(DEFAULT_CELL_SIZE),
  56. cellHeight_(DEFAULT_CELL_HEIGHT),
  57. agentHeight_(DEFAULT_AGENT_HEIGHT),
  58. agentRadius_(DEFAULT_AGENT_RADIUS),
  59. agentMaxClimb_(DEFAULT_AGENT_MAX_CLIMB),
  60. agentMaxSlope_(DEFAULT_AGENT_MAX_SLOPE),
  61. regionMinSize_(DEFAULT_REGION_MIN_SIZE),
  62. regionMergeSize_(DEFAULT_REGION_MERGE_SIZE),
  63. edgeMaxLength_(DEFAULT_EDGE_MAX_LENGTH),
  64. edgeMaxError_(DEFAULT_EDGE_MAX_ERROR),
  65. detailSampleDistance_(DEFAULT_DETAIL_SAMPLE_DISTANCE),
  66. detailSampleMaxError_(DEFAULT_DETAIL_SAMPLE_MAX_ERROR),
  67. ctx_(0),
  68. heightField_(0),
  69. compactHeightField_(0),
  70. contourSet_(0),
  71. polyMesh_(0),
  72. polyMeshDetail_(0),
  73. navMesh_(0)
  74. {
  75. }
  76. NavigationMesh::~NavigationMesh()
  77. {
  78. ReleaseBuildData();
  79. ReleaseNavMesh();
  80. }
  81. void NavigationMesh::RegisterObject(Context* context)
  82. {
  83. context->RegisterFactory<NavigationMesh>();
  84. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Cell Size", GetCellSize, SetCellSize, float, DEFAULT_CELL_SIZE, AM_DEFAULT);
  85. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Cell Height", GetCellHeight, SetCellHeight, float, DEFAULT_CELL_HEIGHT, AM_DEFAULT);
  86. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Agent Height", GetAgentHeight, SetAgentHeight, float, DEFAULT_AGENT_HEIGHT, AM_DEFAULT);
  87. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Agent Radius", GetAgentRadius, SetAgentRadius, float, DEFAULT_AGENT_RADIUS, AM_DEFAULT);
  88. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Agent Max Climb", GetAgentMaxClimb, SetAgentMaxClimb, float, DEFAULT_AGENT_MAX_CLIMB, AM_DEFAULT);
  89. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Agent Max Slope", GetAgentMaxSlope, SetAgentMaxSlope, float, DEFAULT_AGENT_MAX_SLOPE, AM_DEFAULT);
  90. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Region Min Size", GetRegionMinSize, SetRegionMinSize, float, DEFAULT_REGION_MIN_SIZE, AM_DEFAULT);
  91. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Region Merge Size", GetRegionMergeSize, SetRegionMergeSize, float, DEFAULT_REGION_MERGE_SIZE, AM_DEFAULT);
  92. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Edge Max Length", GetEdgeMaxLength, SetEdgeMaxLength, float, DEFAULT_EDGE_MAX_LENGTH, AM_DEFAULT);
  93. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Edge Max Error", GetEdgeMaxError, SetEdgeMaxError, float, DEFAULT_EDGE_MAX_ERROR, AM_DEFAULT);
  94. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Detail Sample Distance", GetDetailSampleDistance, SetDetailSampleDistance, float, DEFAULT_DETAIL_SAMPLE_DISTANCE, AM_DEFAULT);
  95. ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_FLOAT, "Detail Sample Max Error", GetDetailSampleMaxError, SetDetailSampleMaxError, float, DEFAULT_DETAIL_SAMPLE_MAX_ERROR, AM_DEFAULT);
  96. REF_ACCESSOR_ATTRIBUTE(NavigationMesh, VAR_BUFFER, "Navigation Data", GetNavigationDataAttr, SetNavigationDataAttr, PODVector<unsigned char>, Variant::emptyBuffer, AM_FILE | AM_NOEDIT);
  97. }
  98. void NavigationMesh::SetCellSize(float size)
  99. {
  100. cellSize_ = Max(size, M_EPSILON);
  101. }
  102. void NavigationMesh::SetCellHeight(float height)
  103. {
  104. cellHeight_ = Max(height, M_EPSILON);
  105. }
  106. void NavigationMesh::SetAgentHeight(float height)
  107. {
  108. agentHeight_ = Max(height, M_EPSILON);
  109. }
  110. void NavigationMesh::SetAgentRadius(float radius)
  111. {
  112. agentRadius_ = Max(radius, M_EPSILON);
  113. }
  114. void NavigationMesh::SetAgentMaxClimb(float maxClimb)
  115. {
  116. agentMaxClimb_ = Max(maxClimb, M_EPSILON);
  117. }
  118. void NavigationMesh::SetAgentMaxSlope(float maxSlope)
  119. {
  120. agentMaxSlope_ = Max(maxSlope, 0.0f);
  121. }
  122. void NavigationMesh::SetRegionMinSize(float size)
  123. {
  124. regionMinSize_ = Max(size, M_EPSILON);
  125. }
  126. void NavigationMesh::SetRegionMergeSize(float size)
  127. {
  128. regionMergeSize_ = Max(size, M_EPSILON);
  129. }
  130. void NavigationMesh::SetEdgeMaxLength(float length)
  131. {
  132. edgeMaxLength_ = Max(length, M_EPSILON);
  133. }
  134. void NavigationMesh::SetEdgeMaxError(float error)
  135. {
  136. edgeMaxError_ = Max(error, M_EPSILON);
  137. }
  138. void NavigationMesh::SetDetailSampleDistance(float distance)
  139. {
  140. detailSampleDistance_ = Max(distance, M_EPSILON);
  141. }
  142. void NavigationMesh::SetDetailSampleMaxError(float error)
  143. {
  144. detailSampleMaxError_ = Max(error, M_EPSILON);
  145. }
  146. bool NavigationMesh::Build()
  147. {
  148. ReleaseBuildData();
  149. ReleaseNavMesh();
  150. if (!node_)
  151. return false;
  152. PROFILE(BuildNavigationMesh);
  153. {
  154. PROFILE(CollectNavigationGeometry);
  155. // Get Navigable components from child nodes, not from whole scene. This makes it theoretically possible to partition
  156. // the scene into several navigation meshes
  157. PODVector<Navigable*> navigables;
  158. node_->GetComponents<Navigable>(navigables, true);
  159. for (unsigned i = 0; i < navigables.Size(); ++i)
  160. CollectGeometries(navigables[i]->GetNode(), navigables[i]->GetNode());
  161. LOGDEBUG("Navigation mesh has " + String(vertices_.Size()) + " vertices and " + String(indices_.Size()) + " indices");
  162. }
  163. if (!vertices_.Size() || !indices_.Size())
  164. return true; // Nothing to do
  165. {
  166. PROFILE(ProcessNavigationGeometry);
  167. rcConfig cfg;
  168. memset(&cfg, 0, sizeof cfg);
  169. cfg.cs = cellSize_;
  170. cfg.ch = cellHeight_;
  171. cfg.walkableSlopeAngle = agentMaxSlope_;
  172. cfg.walkableHeight = (int)ceilf(agentHeight_ / cfg.ch);
  173. cfg.walkableClimb = (int)floorf(agentMaxClimb_ / cfg.ch);
  174. cfg.walkableRadius = (int)ceilf(agentRadius_ / cfg.cs);
  175. cfg.maxEdgeLen = (int)(edgeMaxLength_ / cellSize_);
  176. cfg.maxSimplificationError = edgeMaxError_;
  177. cfg.minRegionArea = (int)sqrtf(regionMinSize_);
  178. cfg.mergeRegionArea = (int)sqrtf(regionMergeSize_);
  179. cfg.maxVertsPerPoly = 6;
  180. cfg.detailSampleDist = detailSampleDistance_ < 0.9f ? 0.0f : cellSize_ * detailSampleDistance_;
  181. cfg.detailSampleMaxError = cellHeight_ * detailSampleMaxError_;
  182. rcVcopy(cfg.bmin, &worldBoundingBox_.min_.x_);
  183. rcVcopy(cfg.bmax, &worldBoundingBox_.max_.x_);
  184. rcCalcGridSize(cfg.bmin, cfg.bmax, cfg.cs, &cfg.width, &cfg.height);
  185. ctx_ = new rcContext(false);
  186. heightField_ = rcAllocHeightfield();
  187. if (!heightField_)
  188. {
  189. LOGERROR("Could not allocate heightfield");
  190. ReleaseBuildData();
  191. return false;
  192. }
  193. if (!rcCreateHeightfield(ctx_, *heightField_, cfg.width, cfg.height, cfg.bmin, cfg.bmax, cfg.cs, cfg.ch))
  194. {
  195. LOGERROR("Could not create heightfield");
  196. ReleaseBuildData();
  197. return false;
  198. }
  199. unsigned numTriangles = indices_.Size() / 3;
  200. SharedArrayPtr<unsigned char> triAreas(new unsigned char[numTriangles]);
  201. memset(triAreas.Get(), 0, numTriangles);
  202. rcMarkWalkableTriangles(ctx_, cfg.walkableSlopeAngle, &vertices_[0].x_, vertices_.Size(), &indices_[0], numTriangles, triAreas.Get());
  203. rcRasterizeTriangles(ctx_, &vertices_[0].x_, vertices_.Size(), &indices_[0], triAreas.Get(), numTriangles, *heightField_, cfg.walkableClimb);
  204. rcFilterLowHangingWalkableObstacles(ctx_, cfg.walkableClimb, *heightField_);
  205. rcFilterLedgeSpans(ctx_, cfg.walkableHeight, cfg.walkableClimb, *heightField_);
  206. rcFilterWalkableLowHeightSpans(ctx_, cfg.walkableHeight, *heightField_);
  207. compactHeightField_ = rcAllocCompactHeightfield();
  208. if (!compactHeightField_)
  209. {
  210. LOGERROR("Could not allocate create compact heightfield");
  211. ReleaseBuildData();
  212. return false;
  213. }
  214. if (!rcBuildCompactHeightfield(ctx_, cfg.walkableHeight, cfg.walkableClimb, *heightField_, *compactHeightField_))
  215. {
  216. LOGERROR("Could not build compact heightfield");
  217. ReleaseBuildData();
  218. return false;
  219. }
  220. if (!rcErodeWalkableArea(ctx_, cfg.walkableRadius, *compactHeightField_))
  221. {
  222. LOGERROR("Could not erode compact heightfield");
  223. ReleaseBuildData();
  224. return false;
  225. }
  226. if (!rcBuildDistanceField(ctx_, *compactHeightField_))
  227. {
  228. LOGERROR("Could not build distance field");
  229. ReleaseBuildData();
  230. return false;
  231. }
  232. if (!rcBuildRegions(ctx_, *compactHeightField_, 0, cfg.minRegionArea, cfg.mergeRegionArea))
  233. {
  234. LOGERROR("Could not build regions");
  235. ReleaseBuildData();
  236. return false;
  237. }
  238. contourSet_ = rcAllocContourSet();
  239. if (!contourSet_)
  240. {
  241. LOGERROR("Could not allocate contour set");
  242. ReleaseBuildData();
  243. return false;
  244. }
  245. if (!rcBuildContours(ctx_, *compactHeightField_, cfg.maxSimplificationError, cfg.maxEdgeLen, *contourSet_))
  246. {
  247. LOGERROR("Could not create contours");
  248. ReleaseBuildData();
  249. return false;
  250. }
  251. polyMesh_ = rcAllocPolyMesh();
  252. if (!polyMesh_)
  253. {
  254. LOGERROR("Could not allocate poly mesh");
  255. ReleaseBuildData();
  256. return false;
  257. }
  258. if (!rcBuildPolyMesh(ctx_, *contourSet_, cfg.maxVertsPerPoly, *polyMesh_))
  259. {
  260. LOGERROR("Could not triangulate contours");
  261. ReleaseBuildData();
  262. return false;
  263. }
  264. polyMeshDetail_ = rcAllocPolyMeshDetail();
  265. if (!polyMeshDetail_)
  266. {
  267. LOGERROR("Could not allocate detail mesh");
  268. ReleaseBuildData();
  269. return false;
  270. }
  271. if (!rcBuildPolyMeshDetail(ctx_, *polyMesh_, *compactHeightField_, cfg.detailSampleDist, cfg.detailSampleMaxError, *polyMeshDetail_))
  272. {
  273. LOGERROR("Could not build detail mesh");
  274. ReleaseBuildData();
  275. return false;
  276. }
  277. unsigned char* navData = 0;
  278. int navDataSize = 0;
  279. dtNavMeshCreateParams params;
  280. memset(&params, 0, sizeof params);
  281. params.verts = polyMesh_->verts;
  282. params.vertCount = polyMesh_->nverts;
  283. params.polys = polyMesh_->polys;
  284. params.polyAreas = polyMesh_->areas;
  285. params.polyFlags = polyMesh_->flags;
  286. params.polyCount = polyMesh_->npolys;
  287. params.nvp = polyMesh_->nvp;
  288. params.detailMeshes = polyMeshDetail_->meshes;
  289. params.detailVerts = polyMeshDetail_->verts;
  290. params.detailVertsCount = polyMeshDetail_->nverts;
  291. params.detailTris = polyMeshDetail_->tris;
  292. params.detailTriCount = polyMeshDetail_->ntris;
  293. params.walkableHeight = agentHeight_;
  294. params.walkableRadius = agentRadius_;
  295. params.walkableClimb = agentMaxClimb_;
  296. rcVcopy(params.bmin, polyMesh_->bmin);
  297. rcVcopy(params.bmax, polyMesh_->bmax);
  298. params.cs = cfg.cs;
  299. params.ch = cfg.ch;
  300. params.buildBvTree = true;
  301. if (!dtCreateNavMeshData(&params, &navData, &navDataSize))
  302. {
  303. LOGERROR("Could not build Detour navmesh");
  304. ReleaseBuildData();
  305. return false;
  306. }
  307. // Before creating the navmesh (which modifies the data) copy the data for serialization
  308. navigationDataAttr_.Resize(navDataSize);
  309. memcpy(&navigationDataAttr_[0], navData, navDataSize);
  310. ReleaseBuildData();
  311. return CreateNavMesh(navData, navDataSize);
  312. }
  313. }
  314. void NavigationMesh::SetNavigationDataAttr(const PODVector<unsigned char>& data)
  315. {
  316. navigationDataAttr_ = data;
  317. if (!data.Size())
  318. return;
  319. /// \todo Would be preferable not to have to make a copy of the data, however Recast modifies it when creating the navmesh
  320. unsigned char* navData = (unsigned char*)dtAlloc(data.Size(), DT_ALLOC_PERM);
  321. memcpy(navData, &navigationDataAttr_[0], navigationDataAttr_.Size());
  322. CreateNavMesh(navData, data.Size());
  323. }
  324. void NavigationMesh::CollectGeometries(Node* node, Node* baseNode)
  325. {
  326. // If find a navigable from a child node that's not the current base node, abort so we're not going to add the geometry twice
  327. if (node != baseNode && node->HasComponent<Navigable>())
  328. return;
  329. /// \todo Prefer physics geometry if available
  330. PODVector<Drawable*> drawables;
  331. node->GetDerivedComponents<Drawable>(drawables);
  332. for (unsigned i = 0; i < drawables.Size(); ++i)
  333. {
  334. /// \todo Evaluate whether should handle other types. Now StaticModel & TerrainPatch are supported, others skipped
  335. Drawable* drawable = drawables[i];
  336. if (!drawable->IsEnabledEffective())
  337. continue;
  338. unsigned numGeometries = drawable->GetBatches().Size();
  339. unsigned lodLevel;
  340. if (drawable->GetType() == StaticModel::GetTypeStatic())
  341. lodLevel = static_cast<StaticModel*>(drawable)->GetOcclusionLodLevel();
  342. else if (drawable->GetType() == TerrainPatch::GetTypeStatic())
  343. lodLevel = 0;
  344. else
  345. continue;
  346. for (unsigned j = 0; j < numGeometries; ++j)
  347. AddGeometry(node, drawable->GetLodGeometry(j, lodLevel));
  348. }
  349. const Vector<SharedPtr<Node> >& children = node->GetChildren();
  350. for(unsigned i = 0; i < children.Size(); ++i)
  351. CollectGeometries(children[i], baseNode);
  352. }
  353. void NavigationMesh::AddGeometry(Node* node, Geometry* geometry)
  354. {
  355. const unsigned char* vertexData;
  356. const unsigned char* indexData;
  357. unsigned vertexSize;
  358. unsigned indexSize;
  359. unsigned elementMask;
  360. geometry->GetRawData(vertexData, vertexSize, indexData, indexSize, elementMask);
  361. if (!vertexData || !indexData || (elementMask & MASK_POSITION) == 0)
  362. {
  363. LOGERROR("Could not use geometry from node " + node->GetName() + ": vertex or index raw data null or positions missing");
  364. return;
  365. }
  366. unsigned srcIndexStart = geometry->GetIndexStart();
  367. unsigned srcIndexCount = geometry->GetIndexCount();
  368. unsigned srcVertexStart = geometry->GetVertexStart();
  369. unsigned srcVertexCount = geometry->GetVertexCount();
  370. if (!srcIndexCount)
  371. {
  372. LOGERROR("Could not use geometry from node " + node->GetName() + ": no indices");
  373. return;
  374. }
  375. unsigned destVertexStart = vertices_.Size();
  376. // Copy draw range vertices transformed into world space
  377. Matrix3x4 transform = node->GetWorldTransform();
  378. for (unsigned i = srcVertexStart; i < srcVertexStart + srcVertexCount; ++i)
  379. {
  380. Vector3 vertex = transform * *((const Vector3*)(&vertexData[i * vertexSize]));
  381. worldBoundingBox_.Merge(vertex);
  382. vertices_.Push(vertex);
  383. }
  384. // Copy remapped indices
  385. if (indexSize == sizeof(unsigned short))
  386. {
  387. const unsigned short* indices = ((const unsigned short*)indexData) + srcIndexStart;
  388. const unsigned short* indicesEnd = indices + srcIndexCount;
  389. while (indices < indicesEnd)
  390. {
  391. indices_.Push(*indices - srcVertexStart + destVertexStart);
  392. ++indices;
  393. }
  394. }
  395. else
  396. {
  397. const unsigned* indices = ((const unsigned*)indexData) + srcIndexStart;
  398. const unsigned* indicesEnd = indices + srcIndexCount;
  399. while (indices < indicesEnd)
  400. {
  401. indices_.Push(*indices - srcVertexStart + destVertexStart);
  402. ++indices;
  403. }
  404. }
  405. }
  406. bool NavigationMesh::CreateNavMesh(unsigned char* navData, unsigned navDataSize)
  407. {
  408. ReleaseNavMesh();
  409. navMesh_ = dtAllocNavMesh();
  410. if (!navMesh_)
  411. {
  412. LOGERROR("Could not create Detour navmesh");
  413. dtFree(navData);
  414. return false;
  415. }
  416. dtStatus status;
  417. status = navMesh_->init(navData, navDataSize, DT_TILE_FREE_DATA);
  418. if (dtStatusFailed(status))
  419. {
  420. LOGERROR("Could not init Detour navmesh");
  421. ReleaseNavMesh();
  422. dtFree(navData);
  423. return false;
  424. }
  425. LOGDEBUG("Created Detour navmesh, data size " + String(navDataSize) + " bytes");
  426. return true;
  427. }
  428. void NavigationMesh::ReleaseBuildData()
  429. {
  430. delete(ctx_);
  431. ctx_ = 0;
  432. rcFreeHeightField(heightField_);
  433. heightField_ = 0;
  434. rcFreeCompactHeightfield(compactHeightField_);
  435. compactHeightField_ = 0;
  436. rcFreeContourSet(contourSet_);
  437. contourSet_ = 0;
  438. rcFreePolyMesh(polyMesh_);
  439. polyMesh_ = 0;
  440. rcFreePolyMeshDetail(polyMeshDetail_);
  441. polyMeshDetail_ = 0;
  442. vertices_.Clear();
  443. vertices_.Compact();
  444. indices_.Clear();
  445. indices_.Compact();
  446. worldBoundingBox_.defined_ = false;
  447. }
  448. void NavigationMesh::ReleaseNavMesh()
  449. {
  450. dtFreeNavMesh(navMesh_);
  451. navMesh_ = 0;
  452. }
  453. }