Posted on 2016-11-08 21:18
點點滴滴 閱讀(424)
評論(0) 編輯 收藏 引用
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)沒太懂.