Esempio n. 1
0
        public ObjectsADT(string fileName, WDT wdtFile)
        {
            Filename = fileName + "_obj0.adt";
            WDT      = wdtFile;

            Data = new ChunkData(Filename);
        }
Esempio n. 2
0
        public RootADT(string filename, WDT wdt)
        {
            WDT      = wdt;
            Filename = filename;

            Data = new ChunkData(filename + ".adt");
        }
Esempio n. 3
0
 public ADT(string mapName, int x, int y, WDT wdtFile = null)
     : this(string.Format(@"World\Maps\{0}\{0}_{1}_{2}", mapName, x, y), wdtFile)
 {
     World = mapName;
     X     = x;
     Y     = y;
 }
Esempio n. 4
0
        public TexturesADT(string fileName, WDT wdtFile)
        {
            Filename = fileName + "_tex0.adt";
            WDT      = wdtFile;

            Data = new ChunkData(Filename);
        }
Esempio n. 5
0
        public ContinentBuilder(string continent, int startX, int startY, int countX, int countY)
        {
            StartX = startX;
            StartY = startY;
            CountX = countX;
            CountY = countY;

            Continent = continent;
            TileMap = new WDT("World\\Maps\\" + continent + "\\" + continent + ".wdt");
        }
Esempio n. 6
0
        public ADT(string fileName, WDT wdtFile)
        {
            Filename  = fileName;
            Finalized = false;
            WDT       = wdtFile;

            Root     = new RootADT(fileName, wdtFile);
            Textures = new TexturesADT(fileName, wdtFile);
            Objects  = new ObjectsADT(fileName, wdtFile);

            MapChunks = new List <MapChunk>(256);
        }
Esempio n. 7
0
 public void AddWDT(WDT source)
 { }
Esempio n. 8
0
        /*static void TestNavmesh(SharpNav.TiledNavMesh tmesh)
        {
            // Azeroth 28 28 / Deathknell (wow-style coordinates)
            // Outside church: 1843,734 1604,214 94,55994
            // Inside church: 1844,074 1642,581 97,62832
            // Outside spawn: 1672,226 1662,989 139,2343
            // Inside spawn: 1665,264 1678,277 120,5302
            // Outside cave: 2051,3 1807,121 102,5225
            // Inside cave: 2082,813 1950,718 98,04765
            // Outside house: 1861,465 1582,03 92,79533
            // Upstairs house: 1859,929 1560,804 99,07755

            var query = new SharpNav.NavMeshQuery(tmesh, 65535);

            var extents = new SharpNav.Vector3(2.5f, 2.5f, 2.5f);

            // WoW(X, Y, Z) -> SharpNav(Y, Z, X) -- or so I think :-----D
            var posStart = new SharpNav.Vector3(1662.9f, 139.2f, 1672.2f); // Outside spawn
            var posEnd = new SharpNav.Vector3(1678.3f, 120.5f, 1665.3f); // Inside spawn

            SharpNav.Vector3 aStartPos;
            int snRef;
            if (!query.FindNearestPoly(ref posStart, ref extents, out snRef, out aStartPos))
                Console.WriteLine("No start poly");

            //SharpNav.Vector3 rPos;
            //int rRef;
            //if (!query.FindRandomPoint(out rRef, out rPos))
            //    Console.WriteLine("No end poly");

            SharpNav.Vector3 aEndPos;
            int enRef;
            if (!query.FindNearestPoly(ref posEnd, ref extents, out enRef, out aEndPos))
                Console.WriteLine("No end poly");

            var path = new List<int>();
            if (!query.FindPath(snRef, enRef, ref aStartPos, ref aEndPos, path))
                Console.WriteLine("No path");

            //if (!query.FindStraightPath(posStart, posEnd, path.ToArray(), path.Count))
            //    return;
        }*/

        static void ReadWDT()
        {
            string path = "StormwindJail";
            var sw = Stopwatch.StartNew();
            WDT wdt = new WDT(string.Format(@"World\Maps\{0}\{0}.wdt",path));
            sw.Stop();
            if (wdt.IsGlobalModel)
            {
                Console.WriteLine("Loaded {0} chunks from '{1}' in {2}ms", wdt.Data.Chunks.Count, System.IO.Path.GetFileName(path), sw.ElapsedMilliseconds);
                DungeonBuilder d = new DungeonBuilder(path);
                d.Build();
            }
          
        }
Esempio n. 9
0
        public byte[] Build()
        {
            var wdt = new WDT("World\\maps\\" + Dungeon + "\\" + Dungeon + ".wdt");

            if (!wdt.IsGlobalModel || !wdt.IsValid)
                return null;



            Geometry = new Geometry.Geometry {};
            var model = new WMORoot(wdt.ModelFile);
            Geometry.AddDungeon(model, wdt.ModelDefinition);



            if (Geometry.Vertices.Count == 0 && Geometry.Indices.Count == 0)
                throw new InvalidOperationException("Can't build mesh with empty geometry");

            Geometry.SaveWavefrontObject($"{Dungeon}.obj");
            Context = new RecastContext();

            // get raw geometry - lots of slowness here
            float[] vertices;
            int[] triangles;
            byte[] areas;
            Geometry.GetRawData(out vertices, out triangles, out areas);
            Geometry.Indices.Clear();

            float[] bmin, bmax;
            Geometry.CalculateBoundingBox(out bmin, out bmax);
            Geometry.Vertices.Clear();

            // Allocate voxel heightfield where we rasterize our input data to.
            Heightfield hf;
            int width, height;
            Recast.CalcGridSize(bmin, bmax, Config.CellSize, out width, out height);
            if (!Context.CreateHeightfield(out hf, width, height, bmin, bmax, Config.CellSize, Config.CellHeight))
                throw new OutOfMemoryException("CreateHeightfield ran out of memory");

   

            // Find triangles which are walkable based on their slope and rasterize them.
            Context.ClearUnwalkableTriangles(Config.WalkableSlopeAngle, ref vertices, ref triangles, areas);
            Context.RasterizeTriangles(ref vertices, ref triangles, ref areas, hf, Config.WalkableClimb);

          

            // Once all geometry is rasterized, we do initial pass of filtering to
            // remove unwanted overhangs caused by the conservative rasterization
            // as well as filter spans where the character cannot possibly stand.
            Context.FilterLowHangingWalkableObstacles(Config.WalkableClimb, hf);
            Context.FilterLedgeSpans(Config.WalkableHeight, Config.WalkableClimb, hf);
            Context.FilterWalkableLowHeightSpans(Config.WalkableHeight, hf);

           

            // Compact the heightfield so that it is faster to handle from now on.
            // This will result in more cache coherent data as well as the neighbours
            // between walkable cells will be calculated.
            CompactHeightfield chf;
            if (!Context.BuildCompactHeightfield(Config.WalkableHeight, Config.WalkableClimb, hf, out chf))
                throw new OutOfMemoryException("BuildCompactHeightfield ran out of memory");

         

            hf.Delete();

            // Erode the walkable area by agent radius.
            if (!Context.ErodeWalkableArea(Config.WalkableRadius, chf))
                throw new OutOfMemoryException("ErodeWalkableArea ran out of memory");
         

            // Prepare for region partitioning, by calculating distance field along the walkable surface.
            if (!Context.BuildDistanceField(chf))
                throw new OutOfMemoryException("BuildDistanceField ran out of memory");
           

            // Partition the walkable surface into simple regions without holes.
            if (!Context.BuildRegions(chf, Config.BorderSize, Config.MinRegionArea, Config.MergeRegionArea))
                throw new OutOfMemoryException("BuildRegions ran out of memory");
          

            // Create contours.
            ContourSet cset;
            if (!Context.BuildContours(chf, Config.MaxSimplificationError, Config.MaxEdgeLength, out cset))
                throw new OutOfMemoryException("BuildContours ran out of memory");
         

            // Build polygon navmesh from the contours.
            PolyMesh pmesh;
            if (!Context.BuildPolyMesh(cset, Config.MaxVertsPerPoly, out pmesh))
                throw new OutOfMemoryException("BuildPolyMesh ran out of memory");
            

            // Build detail mesh.
            PolyMeshDetail dmesh;
            if (!Context.BuildPolyMeshDetail(pmesh, chf, Config.DetailSampleDistance, Config.DetailSampleMaxError, out dmesh))
                throw new OutOfMemoryException("BuildPolyMeshDetail ran out of memory");
            

            chf.Delete();
            cset.Delete();

            // Set flags according to area types (e.g. Swim for Water)
            pmesh.MarkAll();

            byte[] meshData;
            if (!Detour.CreateNavMeshData(out meshData, pmesh, dmesh, 0, 0, bmin, bmax, Config.WorldWalkableHeight, Config.WorldWalkableRadius, Config.WorldWalkableClimb, Config.CellSize, Config.CellHeight, Config.TileWidth, null))
            {
                pmesh.Delete();
                dmesh.Delete();
                return null;
            }        
            pmesh.Delete();
            dmesh.Delete();
           

            if (Directory.Exists(Dungeon))
                Directory.Delete(Dungeon, true);
            Directory.CreateDirectory(Dungeon);
            
            if (meshData != null)
                File.WriteAllBytes(Dungeon + "\\" + Dungeon + ".dmesh", meshData);

            return meshData;
        }