posts - 311, comments - 0, trackbacks - 0, articles - 0
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理
Compiling the Input
翻译:kun 2014.12.4


The input compile step involves gathering together all the resources needed to build the navigation mesh. This may be as simple as compiling the source geometry into the correct format, or it may be very complex, such as gathering off-mesh connections, mapping triangle type to area, gathering custom processors, etc.
【编译输入数据】这一步在整理一些数据,这些数据和生成NavigationMesh相关。这些数据可能只是简单的将原始的三角形Mesh的顶点数据转换为适合NavigationMesh的数据结构,也可以做其他十分复杂的事情,比如收集分离的mesh之间的连接关系(1),将三角形信息映射到自定义的区域数据上,或者准备好调度一些自定义的处理流程。




The results of this step are the InputGeometry, ProcessorSet, and ConnectionSet objects. (Though finalization of the connection set can be delayed to a later step.)
这一步完成之后,会得到如下的对象: InputGeometry, ProcessorSet, ConnectionSet. (ConnectionSet只是生成NavigationMesh的中间数据,最终数据里不会包含这个对象,但是会包含其信息, 其本身会在之后的步骤里被释放掉)。


There is no standard implementation for compiling the input since the process is specific to the design environment. In Unity the input is gathered from various project assets and scene objects, such as mesh filters. In other environments it might be gathered directly from Maya or 3DSMax data.
编译输入数据是没有标准实现的,这个步骤依赖于特定的平台和环境。在Unity3D里,输入数据来自assets和gameObject,比如mesh filters组件。在其他环境中,可能输入数据直接从Maya或3DSMax模型文件里获取(或者写这些软件的插件)。




Input Geometry


The InputGeometry object consists of standard triangle mesh data (vertices and indices) with additional triangle area assignment. It is derived from the source geometry.
InputGeometry对象除了包含原始的三角网格数据(顶点序列和索引序列),还包括对这些三角形按特定区域进行分组的信息。它继承了原始几何体的信息。


The InputGeometryCompiler and InputGeometryBuilder classes are used to create the input geometry object.
InputGeometryCompiler 和 InputGeometryBuidler 这两个工具类用来生成 Input Geometry对象。


Each triangle in the input geometry is assigned an area based on surface type. Usually, triangles are assigned a default area, such as MaxArea, then special triangles are assigned special areas as needed. For example, 'meadow' and 'sidewalk' triangles may be the default area, while 'water' and 'swamp' triangles are assigned to other areas. Assigning areas during the build process ensures that polygons are properly formed for each type of surface.
每一个三角形都会被归到某种区域内,区域的划分一般依据于数据想表达的地貌。通常来讲,三角形会被指定为一个默认区域类型,比如MaxArea,不过有一些三角形会被指定一个特殊的区域类型。举个例子,用来表达“草地”和“人行道”的三角形会被指定到默认区域,而“水面”和“沼泽”这些三角形则会被指定为其他的区域类型。区域类型的划分可以确保在生成多边形列表时,不会生成跨地貌的多边形。(2)




CopyC#
// Example: Creating a simple input geometry object.
// 例子: 创建一个简单的InputGeometry对象.


// Where 'mesh' is a TriangleMesh object containing all of the input triangles.
// 'mesh'对象是指一个作为原始输入的三角形网格对象.(3)


// Create an area buffer that assigns the default area id to all triangles.
// 创建一个区域buffer,长度为三角形的数量,每一个三角形都会被设置为默认区域。
byte[] areas = NMGen.CreateDefaultAreaBuffer(mesh.triCount);


// Create the builder.
// All triangles with a slope over 45.5f will be re-assigned to NMGen.NullArea.
// 创建builder.
// 所有与xz平面夹角超过45.5度的三角面都会视为不可达,会被设置为 NMGen.NullArea.
InputGeometryBuilder gbuilder = InputGeometryBuilder.Create(mesh, areas, 45.5f);


// Build in a single step.
// Build操作.
gbuilder.BuildAll();


// Get the result.
// 获取结果,为之后的步骤做准备.
InputGeometry geom = gbuilder.Result;




The InputGeometryCompiler class can be used to combine multiple triangle meshes into a single triangle mesh, including area assignment.
InputGeometryCompiler 类可以用来合并多个三角形网格,并且区域信息也会自动合并.




ProcessorSet


The ProcessorSet contains INMGenProcessor objects used to add special behavior to the main build step. A processor may do something simple, such as applying default flags to all polygons (ApplyPolygonFlags), or something complex such as evaluating heightfield intermediates in order to auto-generate off-mesh connections.
ProcessorSet包含多个INMGenProcessor对象,INMGenProcessor是一些在生成NavigationMesh的过程中的特殊操作。一个processor可能只做了一些简单的事情,比如将所有的多边形设置为default;或者一些更复杂的事情,例如计算高度图以便为自动生成分离的Mesh之间的连接关系提供数据支撑。


CopyC#
// Example: Creating a processor set.
// 例子:创建一个ProcessorSet.


// There is a standard set of processors needed for almost every build.
// 系统已经提供了一套标准的processors,可以满足大多数的生成.
myProccessorList.Add(ProcessorSet.GetStandard(ProcessorSet.StandardOptions));


// You can also add other processors, including custom processors of your own.
// 当然你可以添加一些自己的Processor.
myProcessorList.Add(myCustomProcessor);
myProcessorList.Add(myOtherCustomProcessor);


// Create the set.
// 创建ProcessorSet.
ProcessorSet processors = ProcessorSet.Create(myProcessorList.ToArray());




How these processors are used is described further in The Incremental Builder topic.
如何使用这些processor会在Incremental Builder章节里进行介绍.


ConnectionSet


The ConnectionSet defines the off-mesh connections that will be added to the navigation mesh. In some cases they are fully defined during the input build process. In other cases they are generated by custom processor's later in the build process.
ConnectionSet定义了分离的Mesh相互之间是如何连接的,这些信息会被添加到NavigationMesh里。有时候这些信息可以在BuildInput步骤里自动生成,而另外一些时候则是由用户某个自定义的Processor被安排在了特定步骤,从而提供此功能。(4)


The ConnectionSetCompiler can be used to dynamically compile connections for eventual inclusion in the connection set.
ConnectionSetCompiler可以动态的对编译连接关系进行处理,并且可以处理各个连接之间的包含关系。(5)






(1)一些跳跃可达/传送可达之类的自定义行为.
(2)因为不同的区域其路径代价一般会不同,这会用于A*之类的启发函数估价.
(3)其实是u3d的mesh对象,可以通过MeshFilter的mesh属性得到.
(4)没太懂.
(5)没太懂.