mirror of https://github.com/axmolengine/axmol.git
136 lines
4.1 KiB
C++
136 lines
4.1 KiB
C++
/****************************************************************************
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
https://axmolengine.github.io/
|
|
|
|
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:
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
all copies or substantial portions of the Software.
|
|
|
|
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 AX_USE_NAVMESH
|
|
|
|
# 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"
|
|
|
|
NS_AX_BEGIN
|
|
|
|
/**
|
|
* @addtogroup 3d
|
|
* @{
|
|
*/
|
|
class Renderer;
|
|
/** @brief NavMesh: The NavMesh information container, include mesh, tileCache, and so on. */
|
|
class AX_DLL NavMesh : public Ref
|
|
{
|
|
public:
|
|
/**
|
|
Create navmesh
|
|
|
|
@param navFilePath The NavMesh File path.
|
|
@param geomFilePath The geometry File Path,include offmesh information,etc.
|
|
*/
|
|
static NavMesh* create(std::string_view navFilePath, std::string_view geomFilePath);
|
|
|
|
/** 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. */
|
|
void addNavMeshAgent(NavMeshAgent* agent);
|
|
|
|
/** remove a agent from navmesh. */
|
|
void removeNavMeshAgent(NavMeshAgent* agent);
|
|
|
|
/** add a obstacle to navmesh. */
|
|
void addNavMeshObstacle(NavMeshObstacle* obstacle);
|
|
|
|
/** remove a obstacle from navmesh. */
|
|
void removeNavMeshObstacle(NavMeshObstacle* obstacle);
|
|
|
|
/**
|
|
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.
|
|
*/
|
|
void findPath(const Vec3& start, const Vec3& end, std::vector<Vec3>& pathPoints);
|
|
|
|
NavMesh();
|
|
virtual ~NavMesh();
|
|
|
|
protected:
|
|
bool initWithFilePath(std::string_view navFilePath, std::string_view geomFilePath);
|
|
bool read();
|
|
bool loadNavMeshFile();
|
|
bool loadGeomFile();
|
|
void dtDraw();
|
|
void drawAgents();
|
|
void drawObstacles();
|
|
void drawOffMeshConnections();
|
|
|
|
protected:
|
|
dtNavMesh* _navMesh;
|
|
dtNavMeshQuery* _navMeshQuery;
|
|
dtCrowd* _crowed;
|
|
dtTileCache* _tileCache;
|
|
LinearAllocator* _allocator;
|
|
dtTileCacheCompressor* _compressor;
|
|
MeshProcess* _meshProcess;
|
|
GeomData* _geomData;
|
|
|
|
std::vector<NavMeshAgent*> _agentList;
|
|
std::vector<NavMeshObstacle*> _obstacleList;
|
|
NavMeshDebugDraw _debugDraw;
|
|
std::string _navFilePath;
|
|
std::string _geomFilePath;
|
|
bool _isDebugDrawEnabled;
|
|
};
|
|
|
|
/** @} */
|
|
|
|
NS_AX_END
|
|
|
|
#endif // AX_USE_NAVMESH
|
|
|
|
#endif // __CCNAV_MESH_H__
|