private TileBuildTask(int tx, int tz , PolyMeshData polyData , PolyMeshDetailData detailData , ConnectionSet connections , bool bvTreeEnabled , bool isThreadSafe , int priority) : base(priority) { mTileX = tx; mTileZ = tz; mPolyData = polyData; mDetailData = detailData; mConnections = connections; mBVTreeEnabled = bvTreeEnabled; mIsThreadSafe = isThreadSafe; }
/// <summary> /// Creates a new task. /// </summary> /// <remarks> /// <para> /// The task should only be marked as thread-safe if the data parameters are treated /// as immutable while the task is running. /// </para> /// <para> /// Creation will fail on null parameters, invalid tile indices, and an empty /// polygon mesh. /// </para> /// </remarks> /// <param name="tx">The x-index of the tile within the tile grid. (x, z)</param> /// <param name="tz">The z-index of the tile within the tile grid. (x, z)</param> /// <param name="polyData">The polygon mesh data.</param> /// <param name="detailData">The detail mesh data. (Optional)</param> /// <param name="conns">The off-mesh connection set.</param> /// <param name="bvTreeEnabled">True if bounding volumes should be generated.</param> /// <param name="isThreadSafe">True if the task is safe to run on its own thread.</param> /// <param name="priority">The task priority.</param> /// <returns>A new task, or null on error.</returns> public static TileBuildTask Create(int tx, int tz , PolyMeshData polyData , PolyMeshDetailData detailData , ConnectionSet conns , bool bvTreeEnabled , bool isThreadSafe , int priority) { if (tx < 0 || tz < 0 || polyData == null || polyData.polyCount == 0 || conns == null) { return(null); } return(new TileBuildTask(tx, tz , polyData, detailData, conns, bvTreeEnabled, isThreadSafe, priority)); }
/// <summary> /// Draws a debug view of a <see cref="PolyMeshDetailData"/> object. /// </summary> /// <remarks> /// <para> /// Meant to be called during the MonoBehavior.OnRenderObject() method. /// </para> /// </remarks> /// <param name="detailData">The detail mesh to draw.</param> public static void Draw(PolyMeshDetailData detailData) { UnityEngine.Vector3[] verts = VectorHelper.ToUnityVector3Array(ref detailData.verts); DebugDraw.SimpleMaterial.SetPass(0); GL.Begin(GL.TRIANGLES); for (int iMesh = 0; iMesh < detailData.meshCount; iMesh++) { GL.Color(ColorUtil.IntToColor(iMesh, 0.75f)); int pMesh = iMesh * 4; int pVertBase = (int)detailData.meshes[pMesh + 0]; int pTriBase = (int)detailData.meshes[pMesh + 2] * 4; int tCount = (int)detailData.meshes[pMesh + 3]; for (int iTri = 0; iTri < tCount; iTri++) { for (int iVert = 0; iVert < 3; iVert++) { int pVert = pVertBase + (detailData.tris[pTriBase + (iTri * 4 + iVert)]); GL.Vertex(verts[pVert]); } } } GL.End(); // Draw the triangle lines. GL.Begin(GL.LINES); Color portalColor = new Color(0, 0, 0, 0.25f); for (int iMesh = 0; iMesh < detailData.meshCount; iMesh++) { Color meshColor = ColorUtil.IntToColor(iMesh, 1.0f); int pMesh = iMesh * 4; int pVertBase = (int)detailData.meshes[pMesh + 0]; int pTriBase = (int)detailData.meshes[pMesh + 2] * 4; int tCount = (int)detailData.meshes[pMesh + 3]; for (int iTri = 0; iTri < tCount; iTri++) { byte flags = detailData.tris[pTriBase + (iTri * 4 + 3)]; for (int iVert = 0, iPrevVert = 2 ; iVert < 3 ; iPrevVert = iVert++) { if (((flags >> (iPrevVert * 2)) & 0x3) == 0) { GL.Color(meshColor); } else { GL.Color(portalColor); } int pVert = pVertBase + (detailData.tris[pTriBase + (iTri * 4 + iVert)]); int pPrevVert = pVertBase + (detailData.tris[pTriBase + (iTri * 4 + iPrevVert)]); GL.Vertex(verts[pVert]); GL.Vertex(verts[pPrevVert]); } } } GL.End(); }
/// <summary> /// Finalize the task. /// </summary> protected override void FinalizeTask() { mPolyData = null; mDetailData = null; mConnections = null; }
/// <summary> /// Creates a standard <see cref="NavmeshTileBuildData"/> object from the provided /// parameters. /// </summary> /// <remarks> /// <para> /// Errors will be logged to the build context. /// </para> /// </remarks> /// <param name="tx">The x-index of the tile.</param> /// <param name="tz">The z-index of the tile.</param> /// <param name="polyMesh">The polygon mesh data.</param> /// <param name="detailMesh">The detail mesh data. (Optional)</param> /// <param name="connections">The off-mesh connections. (Null allowed.)</param> /// <param name="bvTreeEnabled">True if bounding volumes should be generated.</param> /// <param name="context">The build context.</param> /// <returns>The tile build data, or null on error.</returns> public static NavmeshTileBuildData GetBuildData(BuildContext context , int tx, int tz , PolyMeshData polyMesh, PolyMeshDetailData detailMesh , ConnectionSet connections , bool bvTreeEnabled) { if (context == null) { // Silent. return(null); } Vector3[] verts = null; float[] radii = null; byte[] dirs = null; byte[] areas = null; ushort[] flags = null; uint[] userIds = null; Vector3 bmin = polyMesh.boundsMin; Vector3 bmax = polyMesh.boundsMax; int connCount = (connections == null) ? 0 : connections.GetConnections(bmin.x, bmin.z, bmax.x, bmax.z , out verts, out radii, out dirs, out areas, out flags, out userIds); NavmeshTileBuildData result = new NavmeshTileBuildData( polyMesh.vertCount , polyMesh.polyCount , polyMesh.maxVertsPerPoly , (detailMesh == null ? 0 : detailMesh.vertCount) , (detailMesh == null ? 0 : detailMesh.triCount) , connCount); if (!result.LoadBase(tx, tz, 0, 0 , polyMesh.boundsMin , polyMesh.boundsMax , polyMesh.xzCellSize , polyMesh.yCellSize , polyMesh.walkableHeight , polyMesh.walkableRadius , polyMesh.walkableStep , bvTreeEnabled)) { context.LogError("Base data load failed. Bad configuration data or internal error." , null); return(null); } if (!result.LoadPolys(polyMesh.verts , polyMesh.vertCount , polyMesh.polys , polyMesh.flags , polyMesh.areas , polyMesh.polyCount)) { context.LogError("Polygon load failed. Bad mesh data or internal error.", null); return(null); } if (detailMesh != null) { if (!result.LoadDetail(detailMesh.verts , detailMesh.vertCount , detailMesh.tris , detailMesh.triCount , detailMesh.meshes , detailMesh.meshCount)) { context.LogError("Detail load failed. Bad mesh data or internal error.", null); return(null); } } if (connCount > 0) { if (!result.LoadConns(verts, radii, dirs, areas, flags, userIds, connCount)) { context.LogError("Off-mesh connection load failed. Bad data or internal error." , null); return(null); } } return(result); }