recastnavigation介绍
recastnavigation,非常著名的导航网格。
github地址:https://github.com/recastnavigation/recastnavigation
主要用于客户端导航寻路。
recastnavigation与体素场景
前面2章根据 《天涯明月刀》服务器端3D引擎设计与开发 ,总结了一种表示体素3D场景的方法。
正式开发时,发现对于服务器程序来说,从3D场景模型导出服务器所需的资源文件反而成为最大的难题。
这里发现recastnavigation,做了这部分工作。
recastnavigation在导出导航网格过程中,会导出它的场景体素信息。
因此,开发服务器端体素3D场景,有了新思路。
使用
recastnavigation的体素信息
构建场景struct rcHeightfield { rcHeightfield(); ~rcHeightfield(); int width; ///< The width of the heightfield. (Along the x-axis in cell units.) int height; ///< The height of the heightfield. (Along the z-axis in cell units.) float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)] float cs; ///< The size of each cell. (On the xz-plane.) float ch; ///< The height of each cell. (The minimum increment along the y-axis.) rcSpan** spans; ///< Heightfield of spans (width*height). rcSpanPool* pools; ///< Linked list of span pools. rcSpan* freelist; ///< The next free span. private: // Explicitly-disabled copy constructor and copy assignment operator. rcHeightfield(const rcHeightfield&); rcHeightfield& operator=(const rcHeightfield&); }; struct rcSpan { unsigned int smin : RC_SPAN_HEIGHT_BITS; ///< The lower limit of the span. [Limit: < #smax] unsigned int smax : RC_SPAN_HEIGHT_BITS; ///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT] unsigned int area : 6; ///< The area id assigned to the span. rcSpan* next; ///< The next span higher up in column. };
recastnavigation的体素信息已是最精简的:
a. 基础的width*height*sizeof(int)
b. 某格子上有多个level层的,用 next指针 指向使用
recastnavigation的导航网格数据
做可行走判断导航网格数据量很少
基于recastnavigation的体素3D场景
- 修改recastnavigation的RecastDemo,使之可以导出体素数据
- 编写反解析类,可以从体素数据,重构rcHeightfield,用于获取高度值
- 使用或扣recastnavigation的Detour库代码,做可行走判断。
封装提供简易使用接口。
- 提供是否可行走接口
- 提供射线检测接口
- 提供寻路接口
- 提供模拟接口
简单模拟开房间场景,测试可承载人数、CPU使用情况。