示例#1
0
        private static void ExtractWMOM2s(MapObjectDefinition wmo, WMORoot root, TileModels tileModels)
        {
            var setIndices = new List <int> {
                0
            };

            if (wmo.DoodadSet != 0)
            {
                setIndices.Add(wmo.DoodadSet);
            }

            foreach (var index in setIndices)
            {
                var set = root.DoodadSets[index];
                for (var k = 0; k < set.InstanceCount; k++)
                {
                    var dd = root.DoodadDefinitions[(int)set.FirstInstanceIndex + k];
                    if (string.IsNullOrEmpty(dd.FilePath))
                    {
                        continue;
                    }

                    var model = ExtractModel(wmo, dd);

                    if (model.Vertices.Length < 1)
                    {
                        continue;
                    }
                    tileModels.Models.Add(model);
                }
            }
        }
示例#2
0
        private static void WriteTileM2s(Stream file, TileModels models)
        {
            if (models == null)
            {
                Console.WriteLine("Cannot write null TileModels to file.");
                return;
            }

            var writer = new BinaryWriter(file);

            writer.Write(fileType);

            writer.Write(models.Models.Count);
            foreach (var model in models.Models)
            {
                WriteModel(writer, model);
            }
        }
示例#3
0
        private static TileModels ExtractWDTM2s(IList <MapObjectDefinition> wmos)
        {
            var LoadedWMOIds = new List <uint>();
            var tileModels   = new TileModels
            {
                Models = new List <TileModel>()
            };

            for (var i = 0; i < wmos.Count; i++)
            {
                var wmo = wmos[i];
                if (LoadedWMOIds.Contains(wmo.UniqueId))
                {
                    continue;
                }

                var filePath = wmo.FileName;
                var root     = WMORootParser.Process(manager, filePath);
                if (root == null)
                {
                    Console.WriteLine("Invalid WMORoot returned.");
                    return(null);
                }

                LoadedWMOIds.AddUnique(wmo.UniqueId);
                if (root.DoodadDefinitions == null)
                {
                    Console.WriteLine("No models defined in Root.");
                    return(null);
                }

                ExtractWMOM2s(wmo, root, tileModels);
            }

            return(tileModels);
        }
示例#4
0
        private static TileModels ExtractTileM2s(int tileX, int tileY, ADTFile adt)
        {
            var LoadedWMOIds = new List <uint>();
            var list         = adt.DoodadDefinitions;

            var tileModels = new TileModels
            {
                Models = new List <TileModel>(list.Count)
            };

            foreach (var definition in list)
            {
                if (LoadedM2Ids.Contains(definition.UniqueId))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(definition.FilePath))
                {
                    continue;
                }

                var model = ExtractModel(definition);

                if (model.Vertices.Length < 1)
                {
                    continue;
                }
                tileModels.Models.Add(model);

                LoadedM2Ids.AddUnique(definition.UniqueId);
            }

            var wmoList = adt.ObjectDefinitions;

            foreach (var wmo in wmoList)
            {
                if (LoadedWMOIds.Contains(wmo.UniqueId))
                {
                    continue;
                }

                var worldPos = new Vector3(TerrainConstants.CenterPoint - wmo.Position.X,
                                           wmo.Position.Y,
                                           TerrainConstants.CenterPoint - wmo.Position.Z);
                worldPos = CorrectWMOOrigin(worldPos);

                // If this WMO belongs to another tile, skip it.
                var wmoTileX = (int)((TerrainConstants.CenterPoint - worldPos.Y) / TerrainConstants.TileSize);
                var wmoTileY = (int)((TerrainConstants.CenterPoint - worldPos.X) / TerrainConstants.TileSize);
                if (wmoTileX != tileX || wmoTileY != tileY)
                {
                    continue;
                }

                var filePath = wmo.FileName;
                var root     = WMORootParser.Process(manager, filePath);

                ExtractWMOM2s(wmo, root, tileModels);
                LoadedWMOIds.AddUnique(wmo.UniqueId);
            }

            return(tileModels);
        }
示例#5
0
        private static void WriteTileM2s(Stream file, TileModels models)
        {
            if (models == null)
            {
                Console.WriteLine("Cannot write null TileModels to file.");
                return;
            }

            var writer = new BinaryWriter(file);
            writer.Write(fileType);

            writer.Write(models.Models.Count);
            foreach (var model in models.Models)
            {
                WriteModel(writer, model);
            }
        }
示例#6
0
        private static void ExtractWMOM2s(MapObjectDefinition wmo, WMORoot root, TileModels tileModels)
        {
            var setIndices = new List<int> { 0 };
            if (wmo.DoodadSet != 0) setIndices.Add(wmo.DoodadSet);

            foreach (var index in setIndices)
            {
                var set = root.DoodadSets[index];
                for (var k = 0; k < set.InstanceCount; k++)
                {
                    var dd = root.DoodadDefinitions[(int)set.FirstInstanceIndex + k];
                    if (string.IsNullOrEmpty(dd.FilePath)) continue;

                    var model = ExtractModel(wmo, dd);

                    if (model.Vertices.Length < 1) continue;
                    tileModels.Models.Add(model);
                }
            }
        }
示例#7
0
        private static TileModels ExtractWDTM2s(IList<MapObjectDefinition> wmos)
        {
            var LoadedWMOIds = new List<uint>();
            var tileModels = new TileModels
            {
                Models = new List<TileModel>()
            };

            for (var i = 0; i < wmos.Count; i++)
            {
                var wmo = wmos[i];
                if (LoadedWMOIds.Contains(wmo.UniqueId)) continue;

                var filePath = wmo.FileName;
                var root = WMORootParser.Process(manager, filePath);
                if (root == null)
                {
                    Console.WriteLine("Invalid WMORoot returned.");
                    return null;
                }

                LoadedWMOIds.AddUnique(wmo.UniqueId);
                if (root.DoodadDefinitions == null)
                {
                    Console.WriteLine("No models defined in Root.");
                    return null;
                }

                ExtractWMOM2s(wmo, root, tileModels);
            }

            return tileModels;
        }
示例#8
0
        private static TileModels ExtractTileM2s(int tileX, int tileY, ADTFile adt)
        {
            var LoadedWMOIds = new List<uint>();
            var list = adt.DoodadDefinitions;

            var tileModels = new TileModels
            {
                Models = new List<TileModel>(list.Count)
            };

            foreach (var definition in list)
            {
                if (LoadedM2Ids.Contains(definition.UniqueId)) continue;
                if (string.IsNullOrEmpty(definition.FilePath)) continue;

                var model = ExtractModel(definition);

                if (model.Vertices.Length < 1) continue;
                tileModels.Models.Add(model);

                LoadedM2Ids.AddUnique(definition.UniqueId);
            }

            var wmoList = adt.ObjectDefinitions;
            foreach (var wmo in wmoList)
            {
                if (LoadedWMOIds.Contains(wmo.UniqueId)) continue;

                var worldPos = new Vector3(TerrainConstants.CenterPoint - wmo.Position.X,
                                           wmo.Position.Y,
                                           TerrainConstants.CenterPoint - wmo.Position.Z);
                worldPos = CorrectWMOOrigin(worldPos);

                // If this WMO belongs to another tile, skip it.
                var wmoTileX = (int)((TerrainConstants.CenterPoint - worldPos.Y) / TerrainConstants.TileSize);
                var wmoTileY = (int)((TerrainConstants.CenterPoint - worldPos.X) / TerrainConstants.TileSize);
                if (wmoTileX != tileX || wmoTileY != tileY) continue;

                var filePath = wmo.FileName;
                var root = WMORootParser.Process(manager, filePath);

                ExtractWMOM2s(wmo, root, tileModels);
                LoadedWMOIds.AddUnique(wmo.UniqueId);
            }

            return tileModels;
        }