axmol/core/navmesh/CCNavMesh.h

136 lines
4.1 KiB
C
Raw Normal View History

2015-05-29 16:45:33 +08:00
/****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
https://axis-project.github.io/
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:
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.
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
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. */
void addNavMeshAgent(NavMeshAgent* agent);
2015-05-29 16:45:33 +08:00
/** remove a agent from navmesh. */
void removeNavMeshAgent(NavMeshAgent* agent);
2015-05-29 16:45:33 +08:00
/** add a obstacle to navmesh. */
void addNavMeshObstacle(NavMeshObstacle* obstacle);
2015-05-29 16:45:33 +08:00
/** remove a obstacle from navmesh. */
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.
*/
void findPath(const Vec3& start, const Vec3& end, std::vector<Vec3>& pathPoints);
2015-05-29 16:45:33 +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:
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;
};
/** @} */
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__