示例#1
0
文件: Game.cs 项目: Bia10/meshReader
        public void AddInstance(string path)
        {
            var wdt = new WDT(path);
            if (!wdt.IsValid || !wdt.IsGlobalModel)
                return;

            Components.Add(new WmoDrawer(this, wdt.ModelFile, wdt.ModelDefinition));
        }
示例#2
0
 public void TestWorldModelContinent()
 {
     var wdt = new WDT(@"World\maps\OrgrimmarInstance\OrgrimmarInstance.wdt");
     Assert.IsTrue(wdt.IsValid);
     Assert.IsTrue(wdt.IsGlobalModel);
     Assert.IsNotNullOrEmpty(wdt.ModelFile);
     Assert.IsNotNull(wdt.ModelDefinition);
 }
示例#3
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");
        }
示例#4
0
 public void TestDungeonWithWater()
 {
     MpqManager.Initialize("S:\\World of Warcraft");
     var wdt = new WDT("world\\maps\\orgrimmarinstance\\orgrimmarinstance.wdt");
     Assert.IsTrue(wdt.IsValid && wdt.IsGlobalModel);
     var file = wdt.ModelFile;
     var model = new WorldModelRoot(file);
     var verts = new System.Collections.Generic.List<Vector3>();
     var tris = new System.Collections.Generic.List<Triangle<uint>>();
     WorldModelHandler.InsertModelGeometry(verts, tris, wdt.ModelDefinition, model);
     Assert.IsFalse(verts.Any(v => float.IsNaN(v.X) || float.IsNaN(v.Y) || float.IsNaN(v.Z)));
 }
示例#5
0
        private void UpdateBackground()
        {
            if (_startX == 0 && _startY == 0)
            {
                var files = Directory.GetFiles("S:\\meshReader\\Meshes\\" + _world + "\\");
                var best =
                    files.Where(f => f.EndsWith(".tile")).OrderByDescending(f => new FileInfo(f).Length).FirstOrDefault();
                best = best.Substring(best.LastIndexOf('\\') + 1);
                var tokens = best.Split('_');
                _startX = int.Parse(tokens[1]);
                _startY = int.Parse(tokens[2].Substring(0, tokens[2].IndexOf('.')));
            }

            originTileLabel.Content = OriginTileX + ", " + OriginTileY;
            _pather = new Pather("S:\\meshReader\\Meshes\\" + _world);

            var wdt = new WDT("World\\Maps\\" + _world + "\\" + _world + ".wdt");
            if (!wdt.IsValid || wdt.IsGlobalModel)
                return;                   

            const int totalX = 3;
            const int totalY = 3;

            const int tileSize = 256;
            var result = new Bitmap(totalX * tileSize, totalY * tileSize);
            for (int y = _startY - 1; y <= _startY+1; y++)
            {
                for (int x = _startX - 1; x <= _startX+1; x++)
                {
                    if (!wdt.HasTile(x, y))
                        continue;

                    try
                    {
                        var path = GetMinimapFileByCoords(_world, x, y);
                        var xBegin = (x-(_startX-1))*tileSize;
                        var yBegin = (y-(_startY-1))*tileSize;

                        var image = new Blp(path).GetImage(0);
                        var bitmap = new Bitmap(image);
                        for (int i = 0; i < tileSize; i++)
                        {
                            for (int j = 0; j < tileSize; j++)
                                result.SetPixel(xBegin + i, yBegin + j, bitmap.GetPixel(i, j));
                        }
                    }
                    catch (FileNotFoundException)
                    {

                    }
                }
            }

            // somebody needs to kill WPF developers for this bullshit
            var ms = new MemoryStream();
            result.Save(ms, ImageFormat.Bmp);
            ms.Seek(0, SeekOrigin.Begin);
            var bi = new BitmapImage();
            bi.BeginInit();
            bi.StreamSource = ms;
            bi.EndInit();

            canvas1.Background = new ImageBrush(bi);
        }
示例#6
0
        public void LoadFromContinent(string continent)
        {
            var wdt = new WDT("World\\Maps\\" + continent + "\\" + continent + ".wdt");
            if (!wdt.IsValid || wdt.IsGlobalModel)
                return;

            var result = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            for (int i = 0; i < result.Width; i++)
            {
                for (int j = 0; j < result.Height; j++)
                    result.SetPixel(i, j, Color.FromArgb(0, 29, 40));
            }

            int minX = 65, maxX = 0, minY = 65, maxY = 0;
            for (int y = 0; y < 64; y++)
            {
                for (int x = 0; x < 64; x++)
                {
                    if (!wdt.HasTile(x, y))
                        continue;

                    if (x < minX)
                        minX = x;
                    if (x > maxX)
                        maxX = x;
                    if (y < minY)
                        minY = y;
                    if (y > maxY)
                        maxY = y;
                }
            }

            _totalX = maxX - minX + 1;
            _totalY = maxY - minY + 1;

            for (int y = 0; y < 64; y++)
            {
                for (int x = 0; x < 64; x++)
                {
                    if (!wdt.HasTile(x, y))
                        continue;

                    try
                    {
                        var path = GetMinimapFileByCoords(continent, x, y);
                        var xBegin = GetXBegin(x - minX);
                        var yBegin = GetYBegin(y - minY);

                        var image = new Blp(path).GetImage(0);
                        var resized = ResizeImage(image);
                        for (int i = 0; i < resized.Width; i++)
                        {
                            for (int j = 0; j < resized.Height; j++)
                                result.SetPixel(xBegin + i, yBegin + j, resized.GetPixel(i, j));
                        }
                    }
                    catch (FileNotFoundException)
                    {

                    }
                }
            }

            pictureBox1.Image = result;
            pictureBox1.Visible = true;
        }
示例#7
0
        public byte[] Build(BaseLog log)
        {
            var wdt = new WDT("World\\maps\\" + Dungeon + "\\" + Dungeon + ".wdt");
            if (!wdt.IsGlobalModel || !wdt.IsValid)
                return null;

            InitializeProgress(12);

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

            CompleteWorkUnit();

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

            Log = log;
            Context = new RecastContext();
            Context.SetContextHandler(Log);

            // get raw geometry - lots of slowness here
            float[] vertices;
            int[] triangles;
            byte[] areas;
            Geometry.GetRawData(out vertices, out triangles, out areas);
            Geometry.Triangles.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");

            CompleteWorkUnit();

            // 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);

            CompleteWorkUnit();

            // 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);

            CompleteWorkUnit();

            // 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");

            CompleteWorkUnit();

            hf.Delete();

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

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

            // 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");
            CompleteWorkUnit();

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

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

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

            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;
            }
            
            CompleteWorkUnit();
            pmesh.Delete();
            dmesh.Delete();
            return meshData;
        }
示例#8
0
 public void TestNorthrend()
 {
     var wdt = new WDT(@"World\maps\Northrend\Northrend.wdt");
     Assert.IsTrue(wdt.IsValid);
 }
示例#9
0
 public void TestExpansion01()
 {
     var wdt = new WDT(@"World\maps\Expansion01\Expansion01.wdt");
     Assert.IsTrue(wdt.IsValid);
 }
示例#10
0
 public void TestKalimdor()
 {
     var wdt = new WDT(@"World\maps\Kalimdor\Kalimdor.wdt");
     Assert.IsTrue(wdt.IsValid);
 }
示例#11
0
 public void TestAzeroth()
 {
     var wdt = new WDT(@"World\maps\Azeroth\Azeroth.wdt");
     Assert.IsTrue(wdt.IsValid);
 }