Example #1
0
        private static RegionModels ExtractRegionM2s(WDTFile wdt)
        {
            LoadedM2Ids = new List <uint>(250);
            RegionModels models;

            if (wdt == null)
            {
                return(null);
            }
            if ((wdt.Header.Header1 & WDTFlags.GlobalWMO) != 0)
            {
                // No terrain, load the global WMO
                if (wdt.ObjectDefinitions == null)
                {
                    return(null);
                }

                models = new RegionModels
                {
                    HasTiles      = false,
                    ObjectsByTile = new TileModels[1, 1]
                };

                models.ObjectsByTile[0, 0] = ExtractWDTM2s(wdt.ObjectDefinitions);

                LoadedM2Ids.Clear();
                return(models);
            }


            models = new RegionModels
            {
                HasTiles = true
            };

            for (var tileY = 0; tileY < TerrainConstants.TilesPerMapSide; tileY++)
            {
                for (var tileX = 0; tileX < TerrainConstants.TilesPerMapSide; tileX++)
                {
                    //if (tileX != 36) continue;
                    //if (tileY != 49) continue;

                    if (!wdt.TileProfile[tileX, tileY])
                    {
                        continue;
                    }
                    var adtName = string.Format("{0}_{1:00}_{2:00}", wdt.Name, tileX, tileY);
                    var adt     = ADTParser.Process(manager, wdt.Path, adtName);
                    if (adt == null)
                    {
                        continue;
                    }

                    models.ObjectsByTile[tileX, tileY] = ExtractTileM2s(tileX, tileY, adt);
                }
            }

            LoadedM2Ids.Clear();
            return(models);
        }
Example #2
0
        public static ADT[,] ExtractMapTiles(WDT wdt)
        {
            var mapTiles = new ADT[TerrainConstants.TilesPerMapSide, TerrainConstants.TilesPerMapSide];

            for (var x = 0; x < TerrainConstants.TilesPerMapSide; x++)
            {
                for (var y = 0; y < TerrainConstants.TilesPerMapSide; y++)
                {
                    if (!wdt.TileProfile[y, x])
                    {
                        continue;
                    }
                    if (x != 49 || y != 36)
                    {
                        continue;
                    }

                    var tileId = new TileIdentifier
                    {
                        MapId   = wdt.Entry.Id,
                        MapName = wdt.Name,
                        TileX   = x,
                        TileY   = y
                    };
                    var adt = ADTParser.Process(WDTExtractor.MpqManager, tileId);
                    if (adt == null)
                    {
                        continue;
                    }

                    adt.IsWMOOnly = false;

                    // Load in the WMORoots and their DoodadDefinitions
                    // Load in the ADTs referenced M2Models
                    PrepareChunkInfo(wdt.Manager, adt);

                    ReduceTerrainTris(adt);
                    LoadQuadTree(adt);

                    mapTiles[y, x] = adt;
                }
            }

            return(mapTiles);
        }
        private static void ExtractMapObjects(WDT wdt)
        {
            if (wdt == null)
            {
                return;
            }
            if (wdt.Header.Header1.HasFlag(WDTFlags.GlobalWMO))
            {
                // No terrain, load the global WMO
                if (wdt.WmoDefinitions == null)
                {
                    return;
                }
                ExtractWMOs(wdt.WmoDefinitions);
            }
            else
            {
                for (var tileX = 0; tileX < TerrainConstants.TilesPerMapSide; tileX++)
                {
                    for (var tileY = 0; tileY < TerrainConstants.TilesPerMapSide; tileY++)
                    {
                        if (!wdt.TileProfile[tileY, tileX])
                        {
                            continue;
                        }
                        if (tileX != 49 || tileY != 36)
                        {
                            continue;
                        }

                        ADT adt = null;
                        if (TileExtractor.TerrainInfo != null)
                        {
                            adt = TileExtractor.TerrainInfo[tileY, tileX];
                        }

                        if (adt == null)
                        {
                            var tileId = new TileIdentifier
                            {
                                MapId   = wdt.Entry.Id,
                                MapName = wdt.Entry.InternalName,
                                TileX   = tileX,
                                TileY   = tileY
                            };
                            adt = ADTParser.Process(wdt.Manager, tileId);
                        }
                        if (adt == null)
                        {
                            continue;
                        }

                        ExtractTileWMOs(adt);
                        ExtractTileM2s(adt);
                    }
                }
            }

            PrepareMapWMOs();
            PrepareMapM2s();

            WriteMapM2s(wdt.Entry);
            WriteMapWMOs(wdt.Entry);
        }