internal bool GetMeshBuildData(UnityEngine.Vector3 origin, float tileWorldSize , out NavmeshParams config , out NavmeshTileData[] tiles) { return(GetMeshBuildData(origin, tileWorldSize, new TileZone(0, 0, Width - 1, Depth - 1) , out config, out tiles)); }
/// <summary> /// Generates a human readable report of the mesh data. /// </summary> /// <returns>A human readable report of the mesh data.</returns> public string GetMeshReport() { if (!HasNavmesh) { return("No mesh."); } Navmesh nm = GetNavmesh(); NavmeshParams nmconfig = nm.GetConfig(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine("Navigation mesh report for " + name); if (mBuildInfo != null) { sb.AppendLine("Built from scene: " + mBuildInfo.inputScene); } sb.AppendLine(string.Format("Tiles: {0}, Tile Size: {1:F3}x{2:F3}, Max Polys Per Tile: {3}" , nmconfig.maxTiles, nmconfig.tileWidth, nmconfig.tileDepth, nmconfig.maxPolysPerTile)); int polyCount = 0; int vertCount = 0; int connCount = 0; for (int i = 0; i < nmconfig.maxTiles; i++) { NavmeshTileHeader header = nm.GetTile(i).GetHeader(); if (header.polyCount == 0) { continue; } sb.AppendLine(string.Format( "Tile ({0},{1}): Polygons: {2}, Vertices: {3}, Off-mesh Connections: {4}" , header.tileX, header.tileZ , header.polyCount, header.vertCount , header.connCount)); polyCount += header.polyCount; vertCount += header.vertCount; connCount += header.connCount; } sb.AppendLine(string.Format( "Totals: Polygons: {0}, Vertices: {1}, Off-mesh Connections: {2}" , polyCount, vertCount, connCount)); return(sb.ToString()); }
internal bool GetMeshBuildData(UnityEngine.Vector3 origin, float tileWorldSize, TileZone zone , out NavmeshParams config , out NavmeshTileData[] tiles) { // Is there anything to bake? config = null; tiles = null; int maxPolyCount; int tileCount; BakeableCount(out tileCount, out maxPolyCount); if (tileCount == 0) { return(false); } config = new NavmeshParams(origin.ToVector3() , tileWorldSize, tileWorldSize , Mathf.Max(1, tileCount) , Mathf.Max(1, maxPolyCount)); // Add the tiles. List <NavmeshTileData> ltiles = new List <NavmeshTileData>(); for (int tx = zone.xmin; tx <= zone.xmax; tx++) { for (int tz = zone.zmin; tz <= zone.zmax; tz++) { int trash; NavmeshTileData td = GetTileData(tx, tz, out trash); if (td == null) { // Tile is not available. continue; } ltiles.Add(td); } } tiles = ltiles.ToArray(); return(true); }
/// <summary> /// Loads a navigation mesh. /// </summary> /// <param name="config">The mesh configuration.</param> /// <param name="tiles">The tiles to add to the mesh.</param> /// <param name="buildConfig">The build information. (Optional)</param> /// <returns>The <see cref="NavStatus"/> flags for the operation.</returns> public NavStatus Load(NavmeshParams config , NavmeshTileData[] tiles , NavmeshBuildInfo buildConfig) { if (config == null || tiles == null || tiles.Length > config.maxTiles) { return(NavStatus.Failure | NavStatus.InvalidParam); } Navmesh navmesh; NavStatus status = Navmesh.Create(config, out navmesh); if ((status & NavStatus.Sucess) == 0) { return(status); } foreach (NavmeshTileData tile in tiles) { if (tile == null) { continue; } uint trash; status = navmesh.AddTile(tile, Navmesh.NullTile, out trash); if ((status & NavStatus.Sucess) == 0) { return(status | NavStatus.InvalidParam); } } mDataPack = navmesh.GetSerializedMesh(); if (mDataPack == null) { return(NavStatus.Failure); } mBuildInfo = buildConfig; mVersion++; return(NavStatus.Sucess); }
private void HandleBake() { NavmeshBuild build = Context.Build; NavmeshTileData[] tiles = new NavmeshTileData[1] { build.BuildData.GetTileData(0, 0) }; NavmeshParams nconfig = NavUtil.DeriveConfig(tiles[0]); NavStatus status = build.BuildTarget.Load(nconfig, tiles, NMBEditorUtil.GetConfig(build)); if ((status & NavStatus.Failure) == 0) { EditorUtility.SetDirty((Object)build.BuildTarget); // build.BuildData.SetAsBaked(); build.BuildData.Reset(0, 0); // Don't need to keep the data. } else { Logger.PostError("Bake to target: Target reported failure.", (Object)build.BuildTarget); } }
public void Build() { if (!mBuild) { return; } mBuild.ResetBuild(); // Note: The 'finally' takes care of all cleanup. try { EditorUtility.DisplayCancelableProgressBar("Build & Bake" , "Preparing..." , 0); // Prepare the build. if (!CompileInput()) { return; } if (!InitializeBuild()) { return; } // Build the tiles. NavmeshParams nconfig = null; NavmeshTileData[] tiles = null; bool success = true; if (mBuild.TileSetDefinition == null) { if (!BuildSingleTile()) { return; } tiles = new NavmeshTileData[1] { mBuild.BuildData.GetTileData(0, 0) }; nconfig = NavUtil.DeriveConfig(tiles[0]); } else if (BuildMultiTiled()) { success = mBuild.BuildData.GetMeshBuildData(mBuild.TileSetDefinition.BoundsMin , mBuild.TileSetDefinition.TileWorldSize , out nconfig, out tiles); } else { return; } if (!success) { mContext.PostError("Navigation mesh creation failed.", mBuild); return; } // Bake the mesh. NavStatus nstatus = mBuild.BuildTarget.Load(nconfig, tiles, NMBEditorUtil.GetConfig(mBuild)); if ((nstatus & NavStatus.Sucess) == 0) { mContext.PostError("Bake to target: Target reported failure.", mBuild); } else { EditorUtility.SetDirty((Object)mBuild.BuildTarget); } } finally { mBuild.ResetBuild(); EditorUtility.ClearProgressBar(); } }
internal bool CanLoadFromTarget(BuildContext context, bool fullCheck) { INavmeshData target = BuildTarget; if (target == null || !target.HasNavmesh) { if (context != null) { context.LogError("Build target does not have an existing navigation mesh.", this); } return(false); } NavmeshBuildInfo targetConfig = target.BuildInfo; // Note: The tile size is checked since the original builder // may have supported a tile size not supported by the the standard build. if (targetConfig == null || targetConfig.tileSize >= 0 && targetConfig.tileSize < MinAllowedTileSize) { if (context != null) { context.LogError("Unavailable or unsupported build target configuration.", this); } return(false); } if (!fullCheck) { return(true); } Navmesh nm = target.GetNavmesh(); if (nm == null) { if (context != null) { context.LogError( "Build target does not have an existing navigation mesh. (It lied.)", this); } return(false); } NavmeshParams nmConfig = nm.GetConfig(); if (nmConfig.maxTiles < 2) { if (context != null) { context.LogError("Target navigation mesh is not tiled.", this); } return(false); } int tileCount = 0; for (int i = 0; i < nmConfig.maxTiles; i++) { NavmeshTile tile = nm.GetTile(i); if (tile == null) { continue; } NavmeshTileHeader header = tile.GetHeader(); if (header.polyCount == 0) { continue; } tileCount++; if (header.layer > 0) { if (context != null) { context.LogError( "Target navigation mesh contains layered tiles. (Not supported.)", this); } return(false); } } if (tileCount < 2) { if (context != null) { context.LogError( "Target navigation mesh is either not tiled or has no tiles loaded.", this); } return(false); } return(true); }
public static extern NavStatus dtnmInitTiledNavMesh(NavmeshParams config , ref IntPtr navmesh);
public static extern void dtnmGetParams(IntPtr navmesh , [In, Out] NavmeshParams config);