2015-05-29 16:45:33 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-04-26 22:39:44 +08:00
|
|
|
|
2022-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2021-04-26 22:39:44 +08:00
|
|
|
|
2015-05-29 16:45:33 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-04-26 22:39:44 +08:00
|
|
|
|
2015-05-29 16:45:33 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-04-26 22:39:44 +08:00
|
|
|
|
2015-05-29 16:45:33 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCNAV_MESH_H__
|
|
|
|
#define __CCNAV_MESH_H__
|
|
|
|
|
|
|
|
#include "base/ccConfig.h"
|
|
|
|
#if CC_USE_NAVMESH
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "base/CCRef.h"
|
|
|
|
# include "math/Vec3.h"
|
|
|
|
# include "recast/DetourNavMesh.h"
|
|
|
|
# include "recast/DetourNavMeshQuery.h"
|
|
|
|
# include "recast/DetourCrowd.h"
|
|
|
|
# include "recast/DetourTileCache.h"
|
|
|
|
# include <string>
|
|
|
|
# include <vector>
|
|
|
|
|
|
|
|
# include "navmesh/CCNavMeshAgent.h"
|
|
|
|
# include "navmesh/CCNavMeshDebugDraw.h"
|
|
|
|
# include "navmesh/CCNavMeshObstacle.h"
|
|
|
|
# include "navmesh/CCNavMeshUtils.h"
|
2015-05-29 16:45:33 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup 3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
class Renderer;
|
|
|
|
/** @brief NavMesh: The NavMesh information container, include mesh, tileCache, and so on. */
|
2021-12-25 10:04:45 +08:00
|
|
|
class CC_DLL NavMesh : public Ref
|
|
|
|
{
|
2015-05-29 16:45:33 +08:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Create navmesh
|
|
|
|
|
|
|
|
@param navFilePath The NavMesh File path.
|
|
|
|
@param geomFilePath The geometry File Path,include offmesh information,etc.
|
|
|
|
*/
|
2021-12-26 23:26:34 +08:00
|
|
|
static NavMesh* create(std::string_view navFilePath, std::string_view geomFilePath);
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
/** update navmesh. */
|
|
|
|
void update(float dt);
|
|
|
|
|
|
|
|
/** Internal method, the updater of debug drawing, need called each frame. */
|
|
|
|
void debugDraw(Renderer* renderer);
|
|
|
|
|
|
|
|
/** Enable debug draw or disable. */
|
|
|
|
void setDebugDrawEnable(bool enable);
|
|
|
|
|
|
|
|
/** Check enabled debug draw. */
|
|
|
|
bool isDebugDrawEnabled() const;
|
|
|
|
|
|
|
|
/** add a agent to navmesh. */
|
2021-04-26 22:39:44 +08:00
|
|
|
void addNavMeshAgent(NavMeshAgent* agent);
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
/** remove a agent from navmesh. */
|
2021-04-26 22:39:44 +08:00
|
|
|
void removeNavMeshAgent(NavMeshAgent* agent);
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
/** add a obstacle to navmesh. */
|
2021-04-26 22:39:44 +08:00
|
|
|
void addNavMeshObstacle(NavMeshObstacle* obstacle);
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
/** remove a obstacle from navmesh. */
|
2021-04-26 22:39:44 +08:00
|
|
|
void removeNavMeshObstacle(NavMeshObstacle* obstacle);
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
find a path on navmesh
|
|
|
|
|
|
|
|
@param start The start search position in world coordinate system.
|
|
|
|
@param end The end search position in world coordinate system.
|
|
|
|
@param pathPoints the key points of path.
|
|
|
|
*/
|
2021-04-26 22:39:44 +08:00
|
|
|
void findPath(const Vec3& start, const Vec3& end, std::vector<Vec3>& pathPoints);
|
2015-05-29 16:45:33 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
NavMesh();
|
2015-05-29 16:45:33 +08:00
|
|
|
virtual ~NavMesh();
|
|
|
|
|
|
|
|
protected:
|
2021-12-26 23:26:34 +08:00
|
|
|
bool initWithFilePath(std::string_view navFilePath, std::string_view geomFilePath);
|
2015-05-29 16:45:33 +08:00
|
|
|
bool read();
|
|
|
|
bool loadNavMeshFile();
|
|
|
|
bool loadGeomFile();
|
|
|
|
void dtDraw();
|
|
|
|
void drawAgents();
|
|
|
|
void drawObstacles();
|
|
|
|
void drawOffMeshConnections();
|
|
|
|
|
|
|
|
protected:
|
2021-04-26 22:39:44 +08:00
|
|
|
dtNavMesh* _navMesh;
|
|
|
|
dtNavMeshQuery* _navMeshQuery;
|
|
|
|
dtCrowd* _crowed;
|
|
|
|
dtTileCache* _tileCache;
|
|
|
|
LinearAllocator* _allocator;
|
|
|
|
dtTileCacheCompressor* _compressor;
|
|
|
|
MeshProcess* _meshProcess;
|
|
|
|
GeomData* _geomData;
|
2015-05-29 16:45:33 +08:00
|
|
|
|
|
|
|
std::vector<NavMeshAgent*> _agentList;
|
|
|
|
std::vector<NavMeshObstacle*> _obstacleList;
|
|
|
|
NavMeshDebugDraw _debugDraw;
|
|
|
|
std::string _navFilePath;
|
|
|
|
std::string _geomFilePath;
|
|
|
|
bool _isDebugDrawEnabled;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @} */
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2015-05-29 16:45:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // CC_USE_NAVMESH
|
2015-05-29 16:45:33 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __CCNAV_MESH_H__
|