/// <summary> /// Draws a debug visualization of the navigation mesh. /// </summary> /// <param name="mesh">The mesh to draw.</param> /// <param name="colorByArea"> /// If true, will be colored by polygon area. If false, will be colored by tile index. /// </param> public static void Draw(Navmesh mesh, bool colorByArea) { int count = mesh.GetMaxTiles(); for (int i = 0; i < count; i++) { Draw(mesh.GetTile(i), null, null, 0, colorByArea ? -1 : i); } }
/// <summary> /// Draws a debug visualization of the navigation mesh with the closed nodes highlighted. /// </summary> /// <param name="mesh">The mesh to draw.</param> /// <param name="query">The query which provides the list of closed nodes.</param> public static void Draw(Navmesh mesh, NavmeshQuery query) { int count = mesh.GetMaxTiles(); for (int i = 0; i < count; i++) { Draw(mesh.GetTile(i), query, null, 0, i); } }
/// <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()); }
/// <summary> /// Draws a debug visualization of the navigation mesh with the specified polygons /// highlighted. /// </summary> /// <param name="mesh">The mesh to draw.</param> /// <param name="markPolys"> /// The references of the polygons that should be highlighted. /// </param> /// <param name="polyCount"> /// The number of polygons in the <paramref name="markPolys"/> array. /// </param> public static void Draw(Navmesh mesh, uint[] markPolys, int polyCount) { int count = mesh.GetMaxTiles(); for (int i = 0; i < count; i++) { Draw(mesh.GetTile(i) , null , markPolys , polyCount , i); } }
/// <summary> /// Draws a debug visualization of the specified navigation mesh tile. /// </summary> /// <remarks> /// <para> /// This method is safe to call on empty tile locations. /// </para> /// </remarks> /// <param name="mesh">The mesh.</param> /// <param name="tx">The tile grid x-location.</param> /// <param name="tz">The tile grid z-location.</param> /// <param name="layer">The tile layer.</param> /// <param name="colorByArea"> /// If true, will be colored by polygon area. If false, will be colored by tile index. /// </param> public static void Draw(Navmesh mesh, int tx, int tz, int layer, bool colorByArea) { NavmeshTile tile = mesh.GetTile(tx, tz, layer); if (tile == null) { // No tile at grid location. return; } Draw(tile, null, null, 0 , colorByArea ? -1 : tx.GetHashCode() ^ tz.GetHashCode() ^ layer.GetHashCode()); }
private void SetConfigFromTargetIntern(Navmesh navmesh) { NavmeshBuildInfo targetConfig = BuildTarget.BuildInfo; NMGenParams currConfig = mConfig.GetConfig(); // Note: Must ensure exact match with original configuration. // So this process is using the fields and trusting the // original configuration to have valid values. currConfig.tileSize = targetConfig.tileSize; currConfig.walkableHeight = targetConfig.walkableHeight; currConfig.walkableRadius = targetConfig.walkableRadius; currConfig.walkableStep = targetConfig.walkableStep; currConfig.xzCellSize = targetConfig.xzCellSize; currConfig.yCellSize = targetConfig.yCellSize; currConfig.borderSize = targetConfig.borderSize; mBoundsMin = navmesh.GetConfig().origin; int maxTiles = navmesh.GetMaxTiles(); // Make sure the maximum bounds fits the target mesh. // Note: Will not shrink the existing max bounds. for (int i = 0; i < maxTiles; i++) { NavmeshTile tile = navmesh.GetTile(i); if (tile == null) { continue; } NavmeshTileHeader tileHeader = tile.GetHeader(); if (tileHeader.polyCount == 0) { continue; } mBoundsMax = Vector3.Max(mBoundsMax, tileHeader.boundsMax); } mConfig.SetConfig(currConfig); mIsDirty = true; }
/// <summary> /// Returns the 3D centroids of the provided navigation mesh polygons. /// </summary> /// <remarks> /// <para> /// If a polygon does not exist within the mesh, its associated centroid will not /// be altered. So some centroid data will be invalid if <paramref name="polyCount"/> /// is not equal to the result count. /// </para> /// </remarks> /// <param name="mesh">The navigation mesh containing the polygons.</param> /// <param name="polyRefs">The references of the polygons.</param> /// <param name="polyCount">The number of polygons.</param> /// <param name="centroids"> /// The centroids for the polygons. [Length: >= polyCount] (Out) /// </param> /// <returns>The actual number of polygons found within the mesh. </returns> public static int GetCentroids(Navmesh mesh , uint[] polyRefs , int polyCount , Vector3[] centroids) { int resultCount = 0; int count = mesh.GetMaxTiles(); for (int i = 0; i < count; i++) { resultCount += GetCentroids(mesh.GetTile(i) , polyRefs , polyCount , centroids); if (resultCount == polyRefs.Length) { break; } } return(resultCount); }
public static void OutputVertices() { NavmeshTile tile = navmesh.GetTile(0); float[] headerVerts = new float[tile.GetHeader().vertCount * 3]; org.critterai.Vector3[] buffer = new org.critterai.Vector3[tile.GetHeader().vertCount * 3]; tile.GetVerts(buffer); string filename = "Vertices.txt"; if (File.Exists(filename)) { File.Delete(filename); } File.AppendAllText(filename, "Left List is Raw (vertcount = " + vertCount + "), Right List is From Header (vertcount = " + tile.GetHeader().vertCount + ") (you might see data loss, as converted in/out of grid space.) \n\n"); for (int i = 0; i < vertCount; i++) { File.AppendAllText(filename, "Vertex " + i + ": x: " + vertices[i].x + " y: " + vertices[i].y + " z: " + vertices[i].z + "\t\t|"); File.AppendAllText(filename, "Vertex " + i + ": x: " + buffer[3 * i + 0].x + " y: " + headerVerts[3 * i + 1] + " z: " + headerVerts[3 * i + 2] + "\n"); } }
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); }
/// <summary> /// Returns the 3D centroids of the provided navigation mesh polygons. /// </summary> /// <remarks> /// <para> /// If a polygon does not exist within the mesh, its associated centroid will not /// be altered. So some centroid data will be invalid if <paramref name="polyCount"/> /// is not equal to the result count. /// </para> /// </remarks> /// <param name="mesh">The navigation mesh containing the polygons.</param> /// <param name="polyRefs">The references of the polygons.</param> /// <param name="polyCount">The number of polygons.</param> /// <param name="centroids"> /// The centroids for the polygons. [Length: >= polyCount] (Out) /// </param> /// <returns>The actual number of polygons found within the mesh. </returns> public static int GetCentroids(Navmesh mesh , uint[] polyRefs , int polyCount , Vector3[] centroids) { int resultCount = 0; int count = mesh.GetMaxTiles(); for (int i = 0; i < count; i++) { resultCount += GetCentroids(mesh.GetTile(i) , polyRefs , polyCount , centroids); if (resultCount == polyRefs.Length) break; } return resultCount; }
/// <summary> /// Draws a debug visualization of the specified navigation mesh tile. /// </summary> /// <remarks> /// <para> /// This method is safe to call on empty tile locations. /// </para> /// </remarks> /// <param name="mesh">The mesh.</param> /// <param name="tx">The tile grid x-location.</param> /// <param name="tz">The tile grid z-location.</param> /// <param name="layer">The tile layer.</param> /// <param name="colorByArea"> /// If true, will be colored by polygon area. If false, will be colored by tile index. /// </param> public static void Draw(Navmesh mesh, int tx, int tz, int layer, bool colorByArea) { NavmeshTile tile = mesh.GetTile(tx, tz, layer); if (tile == null) // No tile at grid location. return; Draw(tile, null, null, 0 , colorByArea ? -1 : tx.GetHashCode() ^ tz.GetHashCode() ^ layer.GetHashCode()); }
public void CreateQuery(float fMoveSpeed, float fTurnSpeed) { this.mTurnSpeed = fTurnSpeed; this.mMoveSpeed = fMoveSpeed; NavStatus status = NavmeshQuery.Create(navmesh, mMaxQueryNodes, out query); if ((status & NavStatus.Sucess) == 0) { Debug.LogError( fileName + ": Aborted initialization. Failed query creation: " + status.ToString()); mCrowdManager = null; return; } mCrowdManager = CrowdManager.Create(mMaxCrowdAgents, mMaxAgentRadius, navmesh); if (mCrowdManager == null) { Debug.LogError(fileName + ": Aborted initialization. Failed crowd creation."); } CrowdAvoidanceParams mCrowdParam = CrowdAvoidanceParams.CreateStandardMedium(); mCrowdManager.SetAvoidanceConfig(0, mCrowdParam); mCrowdAgentParams = new CrowdAgentParams(); mCrowdAgentParams.avoidanceType = 0; mCrowdAgentParams.collisionQueryRange = 3.2f; mCrowdAgentParams.height = 1.8f; mCrowdAgentParams.maxAcceleration = 8.0f; mCrowdAgentParams.maxSpeed = this.mMoveSpeed; mCrowdAgentParams.pathOptimizationRange = 12.0f; mCrowdAgentParams.radius = 1.0f; mCrowdAgentParams.separationWeight = 2.0f; mCrowdAgentParams.updateFlags = CrowdUpdateFlags.AnticipateTurns | CrowdUpdateFlags.ObstacleAvoidance | CrowdUpdateFlags.CrowdSeparation | CrowdUpdateFlags.OptimizeVis | CrowdUpdateFlags.OptimizeTopo; polyResult = new uint[300]; pointResult = new Vector3[300]; tileBufferPoints = new Vector3[3000]; pointResultBuffer = new Vector3[300]; polyResultBuffer = new uint[300]; NavmeshTile tile = navmesh.GetTile(0); int count = tile.GetVerts(tileBufferPoints); Debug.Log("Tile " + tile.GetTileRef() + " count:" + count); if (count > 3000) { tileBufferPoints = new Vector3[count]; } tileBufferRef = -1; //NavmeshPoly[] polys=new NavmeshPoly[3000]; //int polyCount; //polyCount=tile.GetPolys(polys); //for (int i = 0; i < polyCount; i++) //{ // NavmeshPoly poly = polys[i]; // //if (poly.Type == NavmeshPolyType.OffMeshConnection) // { // Debug.Log("Poly" + i+"type"+poly.Type.ToString()); // } //} }