Ejemplo n.º 1
0
        /// <summary>
        /// Adds or replaces a tile in the navigation mesh
        /// </summary>
        /// <remarks>The coordinate of the tile is embedded inside the tile data header</remarks>
        public unsafe bool AddOrReplaceTile(byte[] data)
        {
            fixed(byte *dataPtr = data)
            {
                DtTileHeader *header = (DtTileHeader *)dataPtr;
                var           coord  = new int2(header->X, header->Y);

                // Remove old tile if it exists
                RemoveTile(coord);

                TileCoordinates.Add(coord);
                return(Navigation.NavMesh.AddTile(DtNavMesh, new IntPtr(dataPtr), data.Length) == 1);
            }
        }
Ejemplo n.º 2
0
        public unsafe bool GetTileVertices(AiNativeList <float3> vertices, AiNativeList <int> indices)
        {
            if (Data == null || Data.Length == 0)
                return(false);

            fixed(byte *dataPtr = Data)
            {
                DtTileHeader *header = (DtTileHeader *)dataPtr;

                if (header->VertCount == 0)
                {
                    return(false);
                }

                int headerSize = Navigation.DtAlign4(sizeof(DtTileHeader));
                int vertsSize  = Navigation.DtAlign4(sizeof(float) * 3 * header->VertCount);

                byte *ptr = dataPtr;

                ptr += headerSize;

                float3 *vertexPtr = (float3 *)ptr;

                ptr += vertsSize;
                DtPoly *polyPtr = (DtPoly *)ptr;

                for (int i = 0; i < header->VertCount; i++)
                {
                    vertices.Add(vertexPtr[i]);
                }

                for (int i = 0; i < header->PolyCount; i++)
                {
                    // Expand polygons into triangles
                    var poly = polyPtr[i];
                    for (int j = 0; j <= poly.VertexCount - 3; j++)
                    {
                        indices.Add(poly.Vertices[0]);
                        indices.Add(poly.Vertices[j + 1]);
                        indices.Add(poly.Vertices[j + 2]);
                    }
                }

                return(true);
            }
        }
Ejemplo n.º 3
0
        public unsafe void AppendStats(Dictionary <byte, int> stats)
        {
            if (Data == null || Data.Length == 0)
                return;

            fixed(byte *dataPtr = Data)
            {
                DtTileHeader *header = (DtTileHeader *)dataPtr;

                if (header->VertCount == 0)
                {
                    return;
                }

                int headerSize = Navigation.DtAlign4(sizeof(DtTileHeader));
                int vertsSize  = Navigation.DtAlign4(sizeof(float) * 3 * header->VertCount);

                byte *ptr = dataPtr;

                ptr += headerSize;

                float3 *vertexPtr = (float3 *)ptr;

                ptr += vertsSize;
                DtPoly *polyPtr = (DtPoly *)ptr;

                for (int i = 0; i < header->PolyCount; i++)
                {
                    // Expand polygons into triangles
                    DtPoly poly = polyPtr[i];

                    if (!stats.TryGetValue(poly.AreaAndType, out int count))
                    {
                        stats[poly.AreaAndType] = 0;
                    }
                    stats[poly.AreaAndType]++;
                }
            }
        }