Ejemplo n.º 1
0
        /// <summary>
        /// Create tile data from the provided build data.
        /// </summary>
        /// <param name="buildData">The build data.</param>
        /// <returns>A new tile data object, or null on error.</returns>
        public static NavmeshTileData Create(NavmeshTileBuildData buildData)
        {
            if (buildData == null || buildData.IsDisposed)
                return null;

            NavmeshTileData result = new NavmeshTileData();

            if (NavmeshTileEx.dtnmBuildTileData(buildData, result))
                return result;

            return null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create tile data from the provided build data.
        /// </summary>
        /// <param name="buildData">The build data.</param>
        /// <returns>A new tile data object, or null on error.</returns>
        public static NavmeshTileData Create(NavmeshTileBuildData buildData)
        {
            if (buildData == null || buildData.IsDisposed)
            {
                return(null);
            }

            NavmeshTileData result = new NavmeshTileData();

            if (NavmeshTileEx.dtnmBuildTileData(buildData, result))
            {
                return(result);
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a single-tile navigation mesh.
        /// </summary>
        /// <param name="buildData">The tile build data.</param>
        /// <param name="resultMesh">The result mesh.</param>
        /// <returns>The <see cref="NavStatus"/> flags for the operation.
        /// </returns>
        public static NavStatus Create(NavmeshTileBuildData buildData
                                       , out Navmesh resultMesh)
        {
            IntPtr navMesh = IntPtr.Zero;

            NavStatus status = NavmeshEx.dtnmBuildSingleTileMesh(buildData
                                                                 , ref navMesh);

            if (NavUtil.Succeeded(status))
            {
                resultMesh = new Navmesh(navMesh);
            }
            else
            {
                resultMesh = null;
            }

            return(status);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create tile data from the provided build data.
        /// </summary>
        /// <param name="buildData">The build data.</param>
        /// <returns>A new tile data object, or null on error.</returns>
        public static NavmeshTileData Create(NavmeshTileBuildData buildData)
        {
            if (buildData == null || buildData.IsDisposed)
                return null;

            NavmeshTileData result = new NavmeshTileData();

            if (NavmeshTileEx.dtnmBuildTileData(buildData, result))
                return result;

            return null;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a single-tile navigation mesh.
        /// </summary>
        /// <param name="buildData">The tile build data.</param>
        /// <param name="resultMesh">The result mesh.</param>
        /// <returns>The <see cref="NavStatus"/> flags for the operation.
        /// </returns>
        public static NavStatus Create(NavmeshTileBuildData buildData
            , out Navmesh resultMesh)
        {
            IntPtr navMesh = IntPtr.Zero;

            NavStatus status = NavmeshEx.dtnmBuildSingleTileMesh(buildData
                , ref navMesh);

            if (NavUtil.Succeeded(status))
                resultMesh = new Navmesh(navMesh);
            else
                resultMesh = null;

            return status;
        }
    /// <summary>
    /// Loads a single-tile navigation mesh from the provided data.
    /// </summary>
    /// <param name="buildData">The tile build data.</param>
    /// <param name="buildConfig">The build information. (Optional)</param>
    /// <returns>The <see cref="NavStatus"/> flags for the operation.</returns>
    public NavStatus Load(NavmeshTileBuildData buildData, NavmeshBuildInfo buildConfig)
    {
        if (buildData == null || buildData.IsDisposed)
            return NavStatus.Failure | NavStatus.InvalidParam;

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

        if ((status & NavStatus.Sucess) == 0)
            return status;

        mDataPack = navmesh.GetSerializedMesh();

        if (mDataPack == null)
            return NavStatus.Failure;

        mBuildInfo = buildConfig;

        mVersion++;

        return NavStatus.Sucess;
    }
        /// <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;
        }