IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [译]CritterAI官方文档翻译【Creating the Navigation Mesh】

    kun1234567发表于 2014-12-04 02:08:00
    love 0
    Creating the Navigation Mesh
    翻译:kun 2014.12.4


    The final step in the NMGen build process is to create the navigation mesh. As a minimum you must have PolyMesh data. PolyMeshDetail and ConnectionSet data are optional.
    NMGen生成流程的最终步骤就是创建一个NavigationMesh(导航网格).你至少得有PolyMesh数据才可以完成这一步骤.PolyMeshDetail和ConnectionSet是可选项.


    See the The Navigation Mesh topic for the general creation process. This topic will cover two helpful extensions.
    The Navigation Mesh章节介绍了一般性的流程。本章则介绍了两个有用的扩展知识。


    Creating Tile Data
    创建Tile数据.


    Before you can create a navigation mesh you need to convert your source data into tile data. There are various ways of doing this.
    在能创建一个NavigationMesh之前,需要将原始数据转换成Tile数据。有多种办法可以做到这点。


    One method is to use the GetBuildData(BuildContext, Int32, Int32, PolyMeshData, PolyMeshDetailData, ConnectionSet, Boolean) utility method.
    一个办法是使用工具函数 GetBuildData(BuildContext, Int32, Int32, PolyMeshData, PolyMeshDetailData, ConnectionSet, Boolean).


    CopyC#
    // Example: Using the tile build data utility method.
    // 例子:使用工具函数创建Tile数据。
    BuildContext logger = new BuildContext();


    NavmeshTileBuildData tbd = NMBuild.GetBuildData(
    logger
    tileX, tileZ // The tile location. (0, 0) for single tile meshes. // Tile坐标,如果只有一个Tile,传入(0,0)即可;
    , polyData // A PolyMeshData object. // PolyMesh;
    , detailData // Optional PolyMeshDetailData object. // PolyMeshDetail,可选项;
    , connections // Optional ConnectionSet object. // ConnectionSet,可选项;
    , true);


    if (tbd == null)
    {
    // Perform error handling.
    // The build context will contain error messages.
    // 执行错误处理;
    // build context里包含了错误信息;
    }


    // Use the build data to create the navigation mesh...
    // 使用build数据来创建Navmesh.




    Another method is to use the the TileBuildTask class to create the tile data. This method is especially useful if you are building a multi-tile navigation mesh or performing background builds.
    另外一种方法是使用TileBuildTask类来创建Tile数据.这个方法在你处理多tile或者搞多线程处理时特别有用(异步呗)。


    CopyC#
    // Example: Using the tile build task.
    // 例子: 使用TileBuildTask创建数据.


    TileBuildTask task = TileBuildTask.Create(
    tileX, tileZ // The tile location. (0, 0) for single tile meshes. // Tile坐标,如果只有一个Tile,传入(0,0)即可;
    , polyData // A PolyMeshData object. // PolyMesh;
    , detailData // Optional PolyMeshDetailData object. // PolyMeshDetail,可选项;
    , connections // Optional ConnectionSet object. // ConnectionSet,可选项;
    , false // Is the task tread-safe? Not applicable in this case. // 任务是否是否线程安全的?在生成TileData这种应用下没法改。
    , 0); // Task priority. Not applicable in this case. // 任务的优先级。在生成TileData这种应用下没法改。


    task.Run();


    if (task.TaskState == BuildTaskState.Aborted)
    {
    // Perform error handling.
    // Check task messages for details.
    // 执行错误处理;
    // task的messages里包含了错误信息;
    }


    // Get the tile assets.
    // 获取tile结果。
    TileBuildAssets tassets = task.Result;


    // Use the tile data to build the navigation mesh...
    // 使用tile数据创建Navmesh.
    Creating the Navigation Mesh


    Once you have the tile data you can use one of two methods to create the final navigation mesh.
    一旦你获得了Tile数据,你就可以使用两种方法中的任意一种来最终创建navmesh.


    CopyC#
    // Example: Create a single tile mesh.
    // 例子:创建只有一个tile的Navmesh.


    // Where 'buildData' is a NavmeshTileBuildData object.
    // 'buildData'是一个NavmeshTileBuildData对象。


    Navmesh navmesh;
    NavStatus status = Navmesh.Create(buildData, out nm)));


    if ((status & NavStatus.Success) == 0)
    {
    // Perform error handling.
    // 执行错误处理;
    }


    // Use the navitgation mesh...
    // 使用Navmesh...






    CopyC#
    // Example: Create an empty mesh, then add tiles.
    // 例子:创建一个空的Navmesh,然后往其中添加tile.


    // Where 'tiles' is a list containing NavmeshTileData objects.
    // 'tiles'是一个包含多个NavmeshTileData的列表.


    NavmeshParams nconfig = new NavmeshParams(meshOrigin
    , tileSetWidth, tileSetDepth
    , tiles.Count
    , maxPolysPerTile);


    Navmesh navmesh;


    NavStatus status = Navmesh.Create(nconfig, out navmesh)


    if ((status & NavStatus.Success) == 0)
    {
    // Perform error handling.
    // 执行错误处理;
    }


    // Add the tiles to the navigation mesh.
    // 将Tile数据添加到Navmesh.
    foreach (NavmeshTileData tile in tiles)
    {
    // Note: Allowing the navigation mesh to assign the tile reference.
    // 注意: Navmesh会持有Tile对象的引用,因此确保在此前提下不会发生问题。
    uint trash;
    navmesh.AddTile(tile, Navmesh.NullTile, out trash);
    }


    // Use the navigation mesh.
    // 使用Navmesh...


沪ICP备19023445号-2号
友情链接