critterai

http://www.critterai.org/projects/dowloads-archive.html

http://critterai.org/projects/cainav/doc/html/e72bd1ee-04b0-4bbb-a21d-d8d7ecaa11af.htm

[This is preliminary documentation and is subject to change.]

This topic covers the core process used by NMGen to create polygon data that will represent the navigation mesh surface. There are many variations on the mesh generation process, but they all include these steps.

The IncrementalBuilder extension implements this process.

The high level process is as follows:

  1. Voxelization: Create a solid heightfield from the source geometry representing obstructed space.
  2. Generate Regions: Detect the upper surface of the solid heightfield and divide it up into regions of contiguous spans.
  3. Generate Contours: Detect the contours of the regions and form them into simple polygons.
  4. Generate Polygon Mesh: Sub-divide the contours into convex polygons.
  5. Generate Height Detail: Triangulate the polygon mesh and add height detail. (Optional)

Collapse imageVoxelization

Core Class: Heightfield

During voxelization the source geometry is abstracted into a heightfield which represents obstructed space. Then some initial culling of un-walkable surfaces is performed.

Each triangle in the source geometry is voxelized using conservative voxelization and added to the field. Conservative voxelization is an algorithm that ensures the triangle surfaces are completely encompassed by the the generated voxels.

After voxelization, the solid heightfield contains spans that completely encompass the surface of all polygons in the source geometry.

Voxelized Triangle

Expand ImageRegion Generation

Expand ImageContour Generation

Collapse imageConvex Polygon Generation

Core Class: PolyMesh

Many algorithms can only be used with convex polygons. So this step subdivides the simple polygons that make up the contours into a mesh of convex polygons.

 

 Note:

This is the mesh used for most pathfinding purposes.

Below you can see that a mixture of concave polygons have been formed from the contours.

Stage: Polygon Mesh

At the end of this stage, the traversable surface is represented by a mesh of convex polygons.

Collapse imageHeight Detail Generation

Core Class: PolyMeshDetail

In the final stage, the convex polygon mesh is triangulated using Delaunay triangulation so that height detail can be added. Vertices are added internally and to the edges of polygons to ensure the original geometry's surface is adequately followed. (DetailSampleDistance and DetailMaxDeviation)

 

 Note:

Technically, this is an optional step. The detail mesh is not required for pathfinding. But certain queries will return more accurate height data if the detail mesh is available.

Stage: Detail Mesh

Collapse imageSee Also

Concepts

An Introduction to NMGen

Introduction to Heightfields

Reference

IncrementalBuilder

PolyMesh

PolyMeshDetail

Footer image

Project Home | Source Code | License

 

翻译在下面

RecastNavigation-NavMesh生成原理

2017年08月20日 14:47:22 游蓝海 阅读数:9771

本文翻译自CritterAI的文档:http://critterai.org/projects/cainav/doc/html/e72bd1ee-04b0-4bbb-a21d-d8d7ecaa11af.htm

RecastNavigation是一款非常强大的寻路系统,被广泛的应用于各大游戏引擎中。如Unreal,Unity等。我之前也尝试看过部分RecastNavigation源码,添加了一些注释,放到了我自己的github上(https://github.com/youlanhai/recastnavigation-learn)。

CritterAI是基于RecastNavigation原理开发的一套寻路系统,因此理解了CritterAI也就相当于理解了RecastNavigation。因为RecastNavigation的学习资料比较少,当我看到这篇文章的时候,觉得能够帮助我们去深入理解RecastNavigation,所以就翻译下来跟大家分享,有翻译不当的地方尽请指正。以下是原文翻译:

概述

本篇文章介绍了NMGen的核心处理流程。NMGen用于生成多边形数据,代表了导航网格的表面。有很多种网格生成方式,但是他们都包含了下面的一些步骤。 
大体流程如下: 
1. 体素化。从源几何体构造实心的高度场,用来表示不可行走的空间。 
2. 生成地区。将实心高度场的上表面中连续的区间合并为地区。 
3. 生成轮廓。检测地区的轮廓,并构造成简单多边形。 
4. 生成多边形网格。将轮廓分割成凸多边形。 
5. 生成高度细节。将多边形网格三角化,得到高度细节。

体素化(Voxelization)

核心类:Heightfield

在体素1化阶段,源几何体被转换成高度场,用来表示不可行走的空间。一些不可走的表面在这个阶段会被剔除掉2

对于源几何体上的每个三角形,使用“保守体素化算法”(Conservative Voxelization)分割成体素,并加入到高度场中。保守体素化算法确保了每个三角形面,都会被生成的体素完全包围。

体素化阶段后,实心高度场(solid heightfield)包含了很多的区间(span),覆盖了源几何体上的所有面。

体素化

生成地区(Region Generation)

核心类:CompactHeightfield

这一阶段的目标是,近一步定义实体表面上哪部分是可以行走的,以及将这些可行走的部分划分成连续的地区,这些地区可以最终构成简单多边形。

首先,将实心的高度场,转换成一个开放的高度场(open heightfield),用来表示实体表面上那些可以行走的部分。一个开放的高度场,表示位于实体空间表面的地表部分。

在下图中,绿色部分代表开放区间(span)中的地表。这相当于是实心高度场上所有可行走的上表面。注意那些墙,桌子下面的区域,以及走廊扶手上那些比较窄的区域,已经在实心高度场生成的时候被剔除掉了。一些不可行走的区域,比如桌面3楼梯扶手,墙边较窄的位置,目前仍然显示为可行走的。

然后,进一步剔除掉不可行走的区域。在计算完成的时候,开放区间中那些认为可以行走的部分,应该通过下面的测试: 
+ 该区域不能紧挨着障碍物(如,墙,家具等)(使用WalkableRadius作为距离阀值) 
+ 该区域在表面之上没有足够的开放空间(非碰撞区域)。(人在不碰撞到其他物体的情况下,能够合法的移动)(使用WalkableHeight作为高度阀值)

为剩下的所有区间生成邻接信息,用于把他们合并成一个大的面片。该算法使用一个最大垂直步长(WalkableStep4)来决定哪些区间是可以连在一起的。这允许一些特殊的结构能够被考虑进来,比如楼梯,路边,桌面等。例如,构成阶梯的区间能够当做邻居被连接在一起,而桌面上的区间就不能和地板连接在一起。

下图显示的是地区。注意看阶梯上的那些地区,尽管构成的区间并没有直接相连。也需要注意那些桌子上,楼梯扶手,以及所有其他实心高度场上不可走的面,在这个阶段后已经被成功剔除了(黑色表示被剔除的区间)。

在该阶段后,这些相连的地区代表了可行走的面。

生成轮廓(Contour Generation)

核心类:ContourSet

轮廓就是沿着地区边缘“行走”,构成简单多边形。这是从体素空间转换回向量空间的第一步处理。

首先,从地区生成非常精细的多边形。

然后,使用多种算法来完成下面的步骤: 
+ 简化相邻多边形的边缘(地区之间的部分) 
+ 简化边界(边界是没有邻接或邻接了障碍物的轮廓)(EdgeMaxDeviation) 
+ 优化边界的长度。(边界如果太长,不能得到最优的三角形)

下图展示了执行此算法后的轮廓

在该阶段结尾,简单多边形代表了可行走的表面。

生成凸多边形(Convex Polygon Generation)

核心类:PolyMesh

许多算法只能用于凸多边形。因此,这一步需要把轮廓构成的简单多边形转换成凸多边形网格。

注意:许多寻路算法都使用这个网格

下图中,你可以看到由轮廓形成的凸多边形。

在该阶段的结尾,一个凸多边形网格代表了可以行走的表面。

生成高度细节(Height Detail Generation)

核心类:PolyMeshDetail

在这最后的阶段,凸多边形网格会被Delaunay三角化算法三角化,于是可以增加高度的细节。在多边形的内部或者边缘添加顶点,来确保网格与原始几何体表面等价。(DetailSampleDistance和DetailMaxDeviation)

注意:从技术上讲,这一步是可缺省的。细节网格在寻路中不是必须的,但是存在细节网格的情况下,某些查询会返回更加精确的数据。


  1. 译注:体素是空间中的一个有大小的点,实际上就是一个AABB。 
  2. 译注:比如坡度过大的面 
  3. 译注:这里应该是指比较矮的桌子,高度介于MaxClampHeight和WalkableHieght之间。 
  4. 译注:recastnavigation代码中用的是walkableClimb变量。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值