您的位置:首页 > 产品设计 > UI/UE

CritterAI官方文档翻译【The Incremental Builder】

2014-12-04 02:05 323 查看
The Incremental Builder

翻译:kun 2014.12.4

The IncrementalBuilder implements a flexible build process that can be used at design time to create PolyMesh and PolyMeshDetail objects. INMGenProcessor's are used to customize the process for almost any need.

IncrementalBuilder(增量生成器)实现了一个可变的生成流程,可以在设计期(非运行时)创建PolyMesh 和 PolyMeshDetail对象.INMGenProcessor可以用来添加任何自定义的处理方式。

Note Note:

This builder is not suitable for use at run-time since it is designed for flexibility rather than high performance.

注意:

这个生成器不是为运行期使用而设计的,它关注更灵活的可变性,为此放弃了在性能上的高效性。

There are a lot of configuration settings to deal with during the build process. See the NMGenParams documentation for details, including recommendations.

在生成流程里,有大量的配置选项。可以参考NMGenParams获取更多的细致说明,其中也包括一些推荐信息。

Only one builder is needed if the navigation mesh will contain only a single tile. Multi-tile meshes require one builder for each tile. (Builders are single use.)

如果NavigationMesh只有一个Tile(1),那么只需要一个生成器(Builder)对象。对于多Tile的Navmesh,每个tile都需要指定一个生成器.

CopyC#

// Example: A simple NMGen build.

// 例子:一个简单的NMGen生成.

// Where 'mesh' is a TriangleMesh object containing all of the input triangles

// and 'config' is a NMGenParams object containing the configuration.

// 'mesh'对象是指一个作为原始输入的三角形网格对象.

// 'config'是一个包含配置数据的NMGenParams对象.

// Create an input geometry object.

// 创建一个InputGeometry对象;

byte[] areas = NMGen.CreateDefaultAreaBuffer(mesh.triCount);

InputGeometryBuilder gbuilder = InputGeometryBuilder.Create(mesh, areas, 45.5f);

gbuilder.BuildAll();

InputGeometry geom = gbuilder.Result;

// Create the incremental builder.

// 创建一个增量生成器.

NMGenAssetFlag resultFlags = NMGenAssetFlag.PolyMesh | NMGenAssetFlag.DetailMesh;

IncrementalBuilder builder = IncrementalBuilder.Create(config

        , resultFlags

        , geom

        , ProcessorSet.CreateStandard(ProcessorSet.StandardOptions));

// Perform the build and check the result.

// 执行生成操作并检查结果.

builder.BuildAll();

switch (builder.State)

{

        case NMGenState.Aborted:

                // Handle the error.

                // Check builder messages for details.
// 处理错误.
// 检查buidler的messages字段以便获得错误的细节信息.

        case NMGenState.Complete:

                NMGenAssets result = builder.Result;

                // Use the poly and detail mesh data.
// 使用多边形网格和细节数据.

        case NMGenState.NoResult:

                // No result was produced.  

                // Unexpected for single-tile builds.  Not uncommon for multi-tile builds.

                // Check builder messages for details.
// 没有生成结果.
// (2)Unexpected for single-tile builds.  Not uncommon for multi-tile builds.
// 检查buidler的messages字段以便获得错误的细节信息.

}

The Process

生成流程

The incremental builder follows the process described by The Core Build Process topic.

增量生成器的工作流程在The Core Build Process章节里进行详细的说明。

Standard NMGen Build

The Polygon Mesh

The IncrementalBuilder's main output is a PolyMesh object. The polygon mesh is made up of convex polygons with between three and MaxAllowedVertsPerPoly vertices. Each polygon includes edge link, area, flag data.

IncrementalBuilder主要的输出内容是一个多边形网格(PolyMesh对象).多边形网格由3-N个顶点组成(N为MaxAllowedVertsPerPoly指定的数量)的多边形列表构成。每个多边形包含邻接边、区域类型、标志位这些数据。

Polygons may overlap, based on the value of WalkableHeight used during the build.

At the end of the build process all polygons should have at least one flag set. Usually DefaultFlag.

All polygons will have a non-zero area id. (<= MaxArea)

多边形之间可能重叠,取决于可行走的高度(3).

在生成流程完成之后,所有的多边形应该至少包含一种标志位。一般是DefaultFlag。

所有的多边形包含一个ID,该ID的取值范围在(0,MaxArea]之间。MaxArea可以用户指定。

Poly Mesh-Basic

The Detail Mesh

An common optional output of the IncrementalBuilder is a PolyMeshDetail object.

IncrementalBuilder最常用的一个附加输出内容是多边形网格细节信息(PolyMeshDetail对象).

Pathfinding only uses the PolyMesh. For storage efficiency and speed the polygon mesh doesn't have a lot of height accuracy. But some secondary navigation features require more accurate height data. The detail mesh provides the extra detail.

寻路只需要使用PolyMesh就可以完成。为了效率和速度,PolyMesh并不需要高精度的高度信息。但是一些次级导航功能需对高度信息有着更高的精度需求。PolyMeshDetail提供这些额外的细节信息。

The detail mesh consists of sub-meshes, one for each polygon in the polygon mesh. Each sub-mesh is a triangle mesh that contains all the vertices of its associated polygon, plus additional vertices that provide the extra height detail.

PolyMeshDetail包含了若干个子网格(sub-meshes),多边形网格里的每一个多边形都具有此类信息。一个子网格是一个三角网格,包含了所有属于某个多边形的原始三角形顶点信息,以及为了高度信息而额外添加的顶点(4)。

The NMGen Processors

The NMGen processors provided by the ProcessorSet are what give the incremental builder its flexibility and power. Without any processors, only a very simple polygon mesh can be created.

由ProcessorSet提供的NMGenProcessors为增量生成器提供了强大的扩展性。如果没有Processor,只会生成一个非常简单的多边形网格(PolygonMesh).(5)

The NMGen Processors

Processors are called during the post-processor step of each stage, in ascending priority. A processor may perform processing during a single stage or multiple stages.

生成流程中每一个步骤都有后处理阶段(post-processor),处理单元(processor)在这个时机得到执行。一个处理单元(processor)可以在其中一个或多个阶段得到执行。(6)

Any oject that implements INMGenProcessor can act as a processor. The NMGenProcessor abstract class provides a good base to start from.

任何实现INMGenProcessor接口的对象都可以作为一个processor。NMGenProcessor这个虚基类提供了一个好基础,你可以多多利用它。

Two common uses for processors include polygon area and flag assignment.

有两个非常常用的processor,它们是【分配多边形的区域ID】和【分配多边形的标志位】。

Area Assignment

分配区域

Area assignment can happen via the InputGeometry object. But sometimes that isn't convenient or possible. Another choice is to mark areas into the compact heightfield. You can use the AreaBoxMarker, AreaCylinderMarker, and AreaConvexMarker processors to do
this.

分配区域可能在InputGeometry对象生成的时候就做过一次了。但是有时候只在那个阶段做不是很方便(7)。另外一种情况是当你想将一些区域压缩为一个特定地形(8)。你可以使用AreaBoxMarker, AreaCylinderMarker, and AreaConvexMarker processors来做到区域压缩。

Because processors are prioritized, area markers can overwrite each other in useful ways. For example, lets say you have a swamp area with a dry island contained within it. The swamp area needs to be assigned one area while the island needs to be a assigned
a different area. 

If you mark the swamp, the island will be included. This can't be helped since all markers are convex. But by marking the island with a higher priority marker, it will be assigned the proper area.

因为processor之间是有优先级的,所以区域标记可以被任意覆写是非常有用的特点。举个例子,你可以在一块沼泽区域内部标记出一块陆地。只需要为相应的多边形分配不同的区域类型就行了。

如果你标记沼泽,内陆岛也会被一并标记。因为所有多边形区域是凸包,所以这是没办法的事情。但是如果使用一个优先级更高的Marker(9),就可以给内陆岛分配一个合适的区域类型。

Another powerful use of area markers is applying NullArea. Sometimes the build process will create polygons in areas you don't like. For example, there may be clutter on the ground that can technically be walked across, but looks bad when it is. If you mark
the area with 

NullArea, then the area will be excluded from the final polygon mesh.

另外一种很酷的AreaMarker可以将区域标记为NullArea.有时候会生成一些你根本不想要的多边形区域。举个例子,地上有一块实际上可以通过,但是通过路径会非常奇葩的区域。虽然可以为这块区域正确的生成多边形信息,但是你不想要这个奇葩位。如果你将区域标记为NullArea,这个区域就会在生成最终Navmesh时被排除在外。

Polygon Flag Assignment

分配标志位

Polygon flags can be managed entirely in the Navmesh object. But sometimes the flags are best assigned to the PolyMesh during the build process. For example, you may want to assign the 'swim' flag to all 'water' area polygons.

Navmesh对象可以完全控制任意多边形的标志位。但是有些时候在PolyMesh生成的中途来分配标志位会更方便。比如你可能想为所有标记成'water'区域的多边形赋上一个'swim'的标志位(10).

The ApplyPolygonFlags processor can be used to add flags to all polygons.

The AreaFlagMapper processor can be used to add flags to polygons based on the area id of each polygon.

ApplyPolygonFlags这个processor可以用来给所有的多边形指定标志位。

AreaFlagMapper这个processor可以按区域给多边形指定标志位。

(1)Tile是指?

(2)啥意思?

(3)想象一下楼上和楼下的地板,投影到同一个平面之后的情况。

(4)需要考证,是多边形三角化的那几个三角形,还是用来生成polygen的原始三角形集合。

(5)好像我们大部分情况下只需要找到一条合适的路径吧...

(6)为什么要这样做呢?

(7)因为在计算过程中,你得不到全部的数据,只能根据一些极通用的规则来做事,而通常想找到既能处理复杂的需求又在逻辑上支持渐进式处理的规则并不是一件容易的事情。

(8)也许是合并,怎么用的呢?

(9)INMGenProcesser的子类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: