public void AddADT(ADT source) { foreach (var s in new ADT[] { source, source.ADTObjects, /* source.ADTTextures */ }) { foreach (var mc in s.MapChunks) { if (mc.Vertices != null && mc.Vertices.Count() > 0 && mc.Indices != null && mc.Indices.Count > 0) { AddGeometry(mc.Vertices, mc.Indices); } if (mc.WMOVertices != null && mc.WMOVertices.Count > 0 && mc.WMOIndices != null && mc.WMOIndices.Count > 0) { AddGeometry(mc.WMOVertices, mc.WMOIndices); } if (mc.DoodadVertices != null && mc.DoodadVertices.Count > 0 && mc.DoodadIndices != null && mc.DoodadIndices.Count > 0) { AddGeometry(mc.DoodadVertices, mc.DoodadIndices); } } if (s.Liquid != null && s.Liquid.Vertices != null && s.Liquid.Indices != null) { AddGeometry(source.Liquid.Vertices, source.Liquid.Indices); } } }
public void AddADT(ADT s, bool transform = true) { foreach (var mc in s.MapChunks) { AddScene(mc.Scene, transform); } }
public void LoadTileData() { s_Geometry = new Geometry.Geometry(); // First read target tile to verify we have geometry and get bounding box // Read tile s_Tile.Read(); // Generate relevant geometry s_Tile.Generate(); // Append to our geometry s_Geometry.AddADT(s_Tile, false); // Generate the bounding box for the tile // (Because we need to cut the surrounding tiles later) Bounds = Geometry.Geometry.GetBoundingBox(X, Y, s_Geometry.Vertices); // We need to load the surrounding tiles because there sometimes is overlap in geometry to and from different tiles for (var y = Y - 1; y <= Y + 1; y++) { for (var x = X - 1; y <= X + 1; y++) { // Skip target tile as we already added it if (X == x && Y == y) { continue; } // Add a surrounding tile var tile = new ADT(World, x, y); tile.Read(); tile.Generate(); s_Geometry.AddADT(tile, false); } } }
private static void ExtractTileM2s(ADT adt) { foreach (var def in adt.DoodadDefinitions) { ExtractM2Model(def.FilePath); } }
/// <summary> /// /// </summary> /// <param name="modelName"></param> /// <param name="df"></param> public uint AddInstance(string modelName, ADT.Wotlk.MDDF df) { renderLock.WaitOne(); int hash = modelName.ToLower().GetHashCode(); float wowRotY = Utils.SharpMath.mirrorAngle(df.orientationX); float wowRotZ = df.orientationY; float wowRotX = df.orientationZ; wowRotY *= 0.017453f; wowRotZ *= 0.017453f; wowRotX *= 0.017453f; wowRotZ += (float)Math.PI / 2.0f; wowRotZ = Utils.SharpMath.mirrorAngleRadian(wowRotZ); if (BatchRenderers.ContainsKey(hash)) { uint id = BatchRenderers[hash].AddInstance(-Utils.Metrics.MidPoint + df.posX, -Utils.Metrics.MidPoint + df.posZ, df.posY, df.scaleFactor / 1024.0f, new SlimDX.Vector3(wowRotY, wowRotX, wowRotZ)); renderLock.ReleaseMutex(); return id; } try { M2BatchRender rndr = new M2BatchRender(modelName); uint ret = rndr.AddInstance(-Utils.Metrics.MidPoint + df.posX, -Utils.Metrics.MidPoint + df.posZ, df.posY, df.scaleFactor / 1024.0f, new SlimDX.Vector3(wowRotY, wowRotX, wowRotZ)); BatchRenderers.Add(hash, rndr); renderLock.ReleaseMutex(); return ret; } catch (Exception) { renderLock.ReleaseMutex(); throw; } }
/// <summary> /// Run this code at launch /// </summary> void Start() { UserPreferences.Load(); Settings.ApplicationPath = Application.streamingAssetsPath; Settings.Load(); SettingsInit(); ADT.Initialize(CASC.GetComponent <CascHandler>().cascHandler); if (Settings.GetSection("path").GetString("wowsource") == null || Settings.GetSection("path").GetString("wowsource") == "") { } else { CASCConfig config = null; if (Settings.GetSection("misc").GetString("wowsource") == "game") { config = CASCConfig.LoadLocalStorageConfig(Settings.GetSection("path").GetString("selectedpath"), Settings.GetSection("misc").GetString("localproduct")); } else if (Settings.GetSection("misc").GetString("wowsource") == "online") { config = CASCConfig.LoadOnlineStorageConfig(Settings.GetSection("misc").GetString("onlineproduct"), "us", true); } CASC.GetComponent <CascHandler>().InitCasc(config, firstInstalledLocale); } }
private bool LoadTile(int tileX, int tileY) { if (!WDT.HasTile(tileX, tileY)) { return(false); } if (IsTileLoaded(tileX, tileY)) { return(false); } // Generate tile var tile = new ADT(Continent, tileX, tileY, WDT); tile.Read(); tile.Generate(); // Generate renderer var renderer = new ADTRenderer(Controller, tile); renderer.Generate(); renderer.Bind(Controller.Shader); ADTRenderer.Renderers.Add(renderer); return(true); }
public static void WriteTileInfo(FileStream file, ADT adt) { var writer = new BinaryWriter(file); writer.Write(FileTypeId); writer.Write(adt.IsWMOOnly); WriteWMODefs(writer, adt.ObjectDefinitions); if (adt.IsWMOOnly) { return; } WriteM2Defs(writer, adt.DoodadDefinitions); WriteQuadTree(writer, adt.QuadTree); writer.Write(adt.TerrainVertices); for (var x = 0; x < TerrainConstants.ChunksPerTileSide; x++) { for (var y = 0; y < TerrainConstants.ChunksPerTileSide; y++) { var chunk = adt.MapChunks[y, x]; // Whether this chunk has a height map WriteChunkInfo(writer, chunk); } } }
static void ReadMDDF(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); var endPos = fileReader.BaseStream.Position + size; while (fileReader.BaseStream.Position < endPos) { var doodadDefinition = new MapDoodadDefinition(); var nameIndex = fileReader.ReadInt32(); doodadDefinition.FilePath = adt.ModelFiles[nameIndex]; // 4 bytes doodadDefinition.UniqueId = fileReader.ReadUInt32(); // 4 bytes var Y = fileReader.ReadSingle(); var Z = fileReader.ReadSingle(); var X = fileReader.ReadSingle(); doodadDefinition.Position = new Vector3(X, Y, Z); // 12 bytes doodadDefinition.OrientationA = fileReader.ReadSingle(); // 4 Bytes doodadDefinition.OrientationB = fileReader.ReadSingle(); // 4 Bytes doodadDefinition.OrientationC = fileReader.ReadSingle(); // 4 Bytes doodadDefinition.Scale = fileReader.ReadUInt16() / 1024f; // 2 bytes doodadDefinition.Flags = fileReader.ReadUInt16(); // 2 bytes adt.DoodadDefinitions.Add(doodadDefinition); } }
/// <summary> /// Run this code at launch /// </summary> void Start() { Network.Disconnect(); Settings.ApplicationPath = Application.streamingAssetsPath; if (!File.Exists("Settings.ini")) { File.WriteAllLines("Settings.ini", Settings.Data); } else { long length = new System.IO.FileInfo("Settings.ini").Length; if (length > 0) { string[] DataBuffer = File.ReadAllLines("Settings.ini"); for (int i = 0; i < DataBuffer.Length; i++) { Settings.Data[i] = DataBuffer[i]; } } else { File.WriteAllLines("Settings.ini", Settings.Data); // defaults } } SettingsInit(); ADT.Initialize(); if (Settings.Data[2] == Settings.WoWSource.Extracted.ToString()) { DB2.Initialize(); } }
static void ReadMHDR(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); adt.Header.Base = (uint)fileReader.BaseStream.Position; var pad = fileReader.ReadUInt32(); adt.Header.offsInfo = fileReader.ReadUInt32(); adt.Header.offsTex = fileReader.ReadUInt32(); adt.Header.offsModels = fileReader.ReadUInt32(); adt.Header.offsModelIds = fileReader.ReadUInt32(); adt.Header.offsMapObjects = fileReader.ReadUInt32(); adt.Header.offsMapObjectIds = fileReader.ReadUInt32(); adt.Header.offsDoodadDefinitions = fileReader.ReadUInt32(); adt.Header.offsObjectDefinitions = fileReader.ReadUInt32(); adt.Header.offsFlightBoundary = fileReader.ReadUInt32(); adt.Header.offsMH2O = fileReader.ReadUInt32(); var pad3 = fileReader.ReadUInt32(); var pad4 = fileReader.ReadUInt32(); var pad5 = fileReader.ReadUInt32(); var pad6 = fileReader.ReadUInt32(); var pad7 = fileReader.ReadUInt32(); }
public void CreateMinimap(ADT.IADTFile file) { string fileName = ""; if (!gMinimapDir.getMinimapEntry(file.Continent, (int)file.IndexX, (int)file.IndexY, ref fileName)) return; Video.ShaderCollection.TerrainShader.SetValue("minimapMode", true); var oldCamera = Game.GameManager.GraphicsThread.GraphicsManager.Camera; var oldTarget = Game.GameManager.GraphicsThread.GraphicsManager.Device.GetRenderTarget(0); Game.GameManager.GraphicsThread.GraphicsManager.Device.SetRenderTarget(0, mRenderSurface); Game.GameManager.GraphicsThread.GraphicsManager.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.CornflowerBlue, 1, 0); var newCamera = new Video.OrthogonalCamera(1, 1, false); newCamera.ViewFrustum.PassAllTests = true; newCamera.PreventWorldUpdate = true; Game.GameManager.GraphicsThread.GraphicsManager.Camera = newCamera; Game.GameManager.GraphicsThread.GraphicsManager.Camera.SetPosition(new Vector3(Utils.Metrics.Tilesize / 2.0f, Utils.Metrics.Tilesize / 2.0f, 1000.0f), true); file.RenderADT(Matrix.Translation(-file.IndexX * Utils.Metrics.Tilesize + Utils.Metrics.MidPoint, -file.IndexY * Utils.Metrics.Tilesize + Utils.Metrics.MidPoint, 0)); Game.GameManager.GraphicsThread.GraphicsManager.Device.SetRenderTarget(0, oldTarget); Game.GameManager.WorldManager.FogStart = 530.0f; Game.GameManager.GraphicsThread.GraphicsManager.Camera = oldCamera; Texture saveTexture = new Texture(mRenderSurface.Device, 256, 256, 1, Usage.None, Format.X8R8G8B8, Pool.Managed); Surface surf = saveTexture.GetSurfaceLevel(0); Surface.FromSurface(surf, mRenderSurface, Filter.Box, 0); surf.Dispose(); Video.TextureConverter.SaveTextureAsBlp(Video.TextureConverter.BlpCompression.Dxt3, saveTexture, fileName); saveTexture.Dispose(); Video.ShaderCollection.TerrainShader.SetValue("minimapMode", false); }
public static ADT ExtractWMOOnly(WDT wdt) { var tileId = new TileIdentifier { MapId = wdt.Entry.Id, MapName = wdt.Name, TileX = 0, TileY = 0 }; var adt = new ADT(tileId); adt.ObjectDefinitions.Capacity = wdt.WmoDefinitions.Count; foreach (var wmoDefinition in wdt.WmoDefinitions) { adt.ObjectDefinitions.Add(wmoDefinition); } adt.ObjectFiles.Capacity = wdt.WmoFiles.Count; foreach (var wmoFile in wdt.WmoFiles) { adt.ObjectFiles.Add(wmoFile); } foreach (var def in adt.ObjectDefinitions) { LoadWMO(wdt.Manager, def); } adt.IsWMOOnly = true; return(adt); }
static void ReadMVER(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); adt.Version = fileReader.ReadInt32(); }
public void UpdateDeffTree() { if (DeffType == "Range") { if (DeffElement == "Fire") { FireDeffRange(); } else if (DeffElement == "Earth") { EarthDeffRange(); } else if (DeffElement == "Water") { WaterDeffRange(); } else if (DeffElement == "Shadow") { ShadowDeffRange(); } } if (DeffType == "Melee") { if (ADT != null) { ADT.SetActive(false); } } }
/// <summary> /// Run this code at launch /// </summary> void Start() { Settings.ApplicationPath = Application.streamingAssetsPath; if (!File.Exists("Settings.ini")) { //File.Create("Settings.ini"); File.WriteAllLines("Settings.ini", Settings.Data); SettingsInit(); } else { long length = new System.IO.FileInfo("Settings.ini").Length; if (length > 0) { string[] DataBuffer = File.ReadAllLines("Settings.ini"); for (int i = 0; i < DataBuffer.Length; i++) { Settings.Data[i] = DataBuffer[i]; } } else { File.WriteAllLines("Settings.ini", Settings.Data); // defaults } SettingsInit(); } //Debug.Log(Settings.worldScale); ADT.Initialize(); }
static void ReadMH2O(BinaryReader fileReader, ADT adt) { var sig = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); long ofsMH2O = fileReader.BaseStream.Position; MH20Header[] mh20Header = new MH20Header[256]; for (int i = 0; i < 256; i++) { mh20Header[i].ofsData1 = fileReader.ReadUInt32(); mh20Header[i].LayerCount = fileReader.ReadUInt32(); mh20Header[i].ofsData2 = fileReader.ReadUInt32(); } // Rows for (int x = 0; x < 16; x++) { // Columns for (int y = 0; y < 16; y++) { // Indexing is [col, row] adt.LiquidInfo[x, y] = ProcessMH2O(fileReader, mh20Header[x * 16 + y], ofsMH2O); } } }
static void ReadMCNK(BinaryReader br, ADT adt) { for (var i = 0; i < TerrainConstants.ChunksPerTile; i++) { var chunk = ADTChunkReader.ReadChunk(br, adt.MapChunkInfo[i].Offset, adt); adt.Chunks[chunk.Header.IndexX, chunk.Header.IndexY] = chunk; chunk.WaterInfo = adt.LiquidInfo[chunk.Header.IndexX, chunk.Header.IndexY]; } }
private static void PrepareChunkInfo(MpqManager manager, ADT adt) { for (var chunkX = 0; chunkX < TerrainConstants.ChunksPerTileSide; chunkX++) { for (var chunkY = 0; chunkY < TerrainConstants.ChunksPerTileSide; chunkY++) { var chunk = adt.MapChunks[chunkY, chunkX]; foreach (var dRefId in chunk.DoodadRefs) { var dRef = adt.DoodadDefinitions[dRefId]; if (dRef == null) { continue; } if (ModelsToIgnore.Contains(dRef.FilePath)) { continue; } if (LoadedM2Ids.Contains(dRef.UniqueId)) { continue; } M2Model model; if (!WorldObjectExtractor.LoadedM2Models.TryGetValue(dRef.FilePath, out model)) { model = M2ModelParser.Process(manager, dRef.FilePath); WorldObjectExtractor.LoadedM2Models.Add(dRef.FilePath, model); } // This model may have no collision information. If so there is no point saving the data. if (model.BoundingVertices.IsNullOrEmpty()) { // This model has no collision information. We'll ignore it. ModelsToIgnore.Add(dRef.FilePath); WorldObjectExtractor.LoadedM2Models.Remove(dRef.FilePath); } // At this point, we're using the model for collision stuff PrepareM2Info(dRef, model); LoadedM2Ids.Add(dRef.UniqueId); } foreach (var oRefId in chunk.ObjectRefs) { var oRef = adt.ObjectDefinitions[oRefId]; if (oRef == null) { continue; } LoadWMO(manager, oRef); } PrepareChunk(adt, chunkX, chunkY); } } }
private void ProcessMessage(string fullPath) { string msgtext = ""; int i = 0; while (i < 5) { try { msgtext = File.ReadAllText(fullPath); break; } catch { } Thread.Sleep(200); i++; if (i == 5) { EventLog.WriteEntry("Could not read text from file due to file locking issues.", EventLogEntryType.Error); return; } } try { MessageHL7 msg = new MessageHL7(msgtext); //this creates an entire heirarchy of objects. if (msg.MsgType == MessageType.ADT) { if (IsVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Processed ADT message", EventLogEntryType.Information); } ADT.ProcessMessage(msg, IsStandalone, IsVerboseLogging); } else if (msg.MsgType == MessageType.SIU && !IsStandalone) //appointments don't get imported if standalone mode. { if (IsVerboseLogging) { EventLog.WriteEntry("OpenDentHL7", "Processed SUI message", EventLogEntryType.Information); } SIU.ProcessMessage(msg, IsStandalone, IsVerboseLogging); } } catch (Exception ex) { EventLog.WriteEntry(ex.Message + "\r\n" + ex.StackTrace, EventLogEntryType.Error); return; } //we won't be processing DFT messages. //else if(msg.MsgType==MessageType.DFT) { //ADT.ProcessMessage(msg); //} try { File.Delete(fullPath); } catch (Exception ex) { EventLog.WriteEntry("Delete failed for " + fullPath + "\r\n" + ex.Message, EventLogEntryType.Error); } }
void ShadowDeffRange() { if (ADT != null) { ADT.SetActive(false); } SDR.SetActive(true); ADT = SDR; PlayerPrefs.SetInt("ADT", 3); PlayerPrefs.Save(); }
void WaterDeffRange() { if (ADT != null) { ADT.SetActive(false); } WDR.SetActive(true); ADT = WDR; PlayerPrefs.SetInt("ADT", 2); PlayerPrefs.Save(); }
private static void PrepareChunk(ADT adt, int chunkX, int chunkY) { var chunk = adt.MapChunks[chunkY, chunkX]; if (chunk == null) { return; } var min = float.MaxValue; var max = float.MinValue; foreach (var height in chunk.Heights.Heights) { min = Math.Min(height, min); max = Math.Max(height, max); } chunk.IsFlat = (Math.Abs(max - min) < 0.1f); if (chunk.IsFlat) { Console.WriteLine("Found flat chunk: {0},{1}.", chunk.Header.IndexX, chunk.Header.IndexY); } chunk.WaterInfo = adt.LiquidInfo[chunkY, chunkX]; PrepareWaterInfo(chunk.WaterInfo); // Replace the model and wmo refs with their respective UniqueIds for (var i = 0; i < chunk.DoodadRefs.Count; i++) { var doodadRef = chunk.DoodadRefs[i]; var def = adt.DoodadDefinitions[doodadRef]; if (def == null || ModelsToIgnore.Contains(def.FilePath)) { chunk.DoodadRefs[i] = int.MinValue; continue; } var uniqueId = def.UniqueId; chunk.DoodadRefs[i] = (int)uniqueId; } for (var i = 0; i < chunk.ObjectRefs.Count; i++) { var objectRef = chunk.ObjectRefs[i]; var def = adt.ObjectDefinitions[objectRef]; if (def == null) { chunk.ObjectRefs[i] = int.MinValue; continue; } var uniqueId = def.UniqueId; chunk.ObjectRefs[i] = (int)uniqueId; } }
void EarthDeffRange() { if (ADT != null) { ADT.SetActive(false); } EDR.SetActive(true); ADT = EDR; PlayerPrefs.SetInt("ADT", 1); PlayerPrefs.Save(); }
void FireDeffRange() { if (ADT != null) { ADT.SetActive(false); } FDR.SetActive(true); ADT = FDR; PlayerPrefs.SetInt("ADT", 0); PlayerPrefs.Save(); }
public void TestGameAdt() { MpqManager.Initialize("S:\\WoW"); var test = new ADT("World\\maps\\Northrend\\Northrend_43_29.adt"); test.Read(); Assert.AreEqual(test.MapChunks.Length, 16 * 16); Assert.IsNotNull(test.DoodadHandler.Vertices); Assert.IsNotNull(test.DoodadHandler.Triangles); }
static void ReadMWID(BinaryReader fileReader, ADT adt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); uint count = size / 4; for (int i = 0; i < count; i++) { adt.ObjectFileOffsets.Add(fileReader.ReadInt32()); } }
public static ADTChunk ReadChunk(BinaryReader fileReader, uint mcnkOffset, ADT parent) { var chunk = new ADTChunk(); fileReader.BaseStream.Position = mcnkOffset; // Read the header ReadMCNK(fileReader, chunk); if (chunk.Header.offsColorValues != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.offsColorValues; ReadMCCV(fileReader, chunk); } if (chunk.Header.ofsHeight != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsHeight; ReadMCVT(fileReader, chunk); } if (chunk.Header.ofsNormal != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsNormal; ReadMCNR(fileReader, chunk); } if (chunk.Header.ofsLayer != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsLayer; ReadMCLY(fileReader, chunk); } if (chunk.Header.ofsRefs != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsRefs; ReadMCRF(fileReader, chunk); } if (chunk.Header.ofsShadow != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsShadow; ReadMCSH(fileReader, chunk); } if (chunk.Header.ofsAlpha != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsAlpha; ReadMCAL(fileReader, chunk); } if (chunk.Header.ofsSndEmitters != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsSndEmitters; ReadMCSE(fileReader, chunk); } return(chunk); }
public static ADTChunk Process(BinaryReader fileReader, uint mcnkOffset, ADT parent) { var chunk = new ADTChunk(); fileReader.BaseStream.Position = mcnkOffset; // Read the header ReadMCNK(fileReader, chunk); if (chunk.Header.offsColorValues != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.offsColorValues; ReadMCCV(fileReader, chunk); } if (chunk.Header.ofsHeight != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsHeight; ReadMCVT(fileReader, chunk); } if (chunk.Header.ofsNormal != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsNormal; ReadMCNR(fileReader, chunk); } if (chunk.Header.ofsLayer != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsLayer; ReadMCLY(fileReader, chunk); } if (chunk.Header.ofsRefs != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsRefs; ReadMCRF(fileReader, chunk); } if (chunk.Header.ofsShadow != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsShadow; ReadMCSH(fileReader, chunk); } if (chunk.Header.ofsAlpha != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsAlpha; ReadMCAL(fileReader, chunk); } if (chunk.Header.ofsSndEmitters != 0) { fileReader.BaseStream.Position = mcnkOffset + chunk.Header.ofsSndEmitters; ReadMCSE(fileReader, chunk); } return chunk; }
public static ADT GetAdt(string world, int x, int y) { ADT adt = null; if (Cache.Adt.TryGetValue(new Tuple <int, int>(x, y), out adt)) { return(adt); } adt = new ADT(GetAdtPath(world, x, y)); adt.Read(); Cache.Adt.Add(new Tuple <int, int>(x, y), adt); return(adt); }
static void ReadADT() { //var adt = new ADT("Azeroth", 28, 28); //var adt = new ADT("Kalimdor", 32, 36); var adt = new ADT("PvPZone01", 32, 30); adt.Read(); var geom = new Geometry(); geom.AddADT(adt); geom.SaveWavefrontObject(Path.GetFileNameWithoutExtension(adt.Filename) + ".obj"); }
public static ADT GetAdt(string world, int x, int y) { //if (Cache.Adt.TryGetValue(new Tuple<int, int>(x, y), out adt)) // return adt; ADT adt = new ADT(GetAdtPath(world, x, y)); if (adt.HasObjectData) { adt.Read(); } //Cache.Adt.Add(new Tuple<int, int>(x, y), adt); return(adt); }
/// <summary> /// Write the given ADT's heightfield to disk /// </summary> public static void WriteHeightfield(ADT adt) { var path = Path.Combine(WCellTerrainSettings.SimpleMapDir, ((int)adt.Terrain.MapId).ToString()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } using (var file = File.Create(GetFileName(adt.Terrain.MapId, adt.TileX, adt.TileY))) { using (var writer = new BinaryWriter(file)) { for (var y = 0; y < TerrainConstants.ChunksPerTileSide; ++y) { for (var unitY = 0; unitY <= TerrainConstants.UnitsPerChunkSide; ++unitY) { for (var x = 0; x < TerrainConstants.ChunksPerTileSide; ++x) { var chunk = adt.Chunks[x, y]; var heights = chunk.Heights.GetLowResMapMatrix(); //var holes = (chunk.HolesMask > 0) ? chunk.HolesMap : ADT.EmptyHolesArray; // Add the height map values, inserting them into their correct positions for (var unitX = 0; unitX <= TerrainConstants.UnitsPerChunkSide; ++unitX) { //var tileX = (x * TerrainConstants.UnitsPerChunkSide) + unitX; //var tileY = (y * TerrainConstants.UnitsPerChunkSide) + unitY; //var xPos = TerrainConstants.CenterPoint // - (TileX * TerrainConstants.TileSize) // - (tileX * TerrainConstants.UnitSize); //var yPos = TerrainConstants.CenterPoint // - (TileY * TerrainConstants.TileSize) // - (tileY * TerrainConstants.UnitSize); var h = (heights[unitX, unitY] + chunk.MedianHeight); // Write height writer.Write(h); //tileHolesMap[tileX, tileY] = holes[unitX / 2, unitY / 2]; } } } } } } }
protected ObjectDataHandler(ADT adtFile) { Source = adtFile; }
public static void ExtractTileWMOs(ADT adt) { var list = adt.ObjectDefinitions; ExtractWMOs(list); }
private static void ReduceTerrainTris(ADT adt) { adt.GenerateHeightVertexAndIndices(); }
private static void PrepareChunk(ADT adt, int chunkX, int chunkY) { var chunk = adt.MapChunks[chunkY, chunkX]; if (chunk == null) return; var min = float.MaxValue; var max = float.MinValue; foreach (var height in chunk.Heights.Heights) { min = Math.Min(height, min); max = Math.Max(height, max); } chunk.IsFlat = (Math.Abs(max - min) < 0.1f); if (chunk.IsFlat) Console.WriteLine("Found flat chunk: {0},{1}.", chunk.Header.IndexX, chunk.Header.IndexY); chunk.WaterInfo = adt.LiquidInfo[chunkY, chunkX]; PrepareWaterInfo(chunk.WaterInfo); // Replace the model and wmo refs with their respective UniqueIds for (var i = 0; i < chunk.DoodadRefs.Count; i++) { var doodadRef = chunk.DoodadRefs[i]; var def = adt.DoodadDefinitions[doodadRef]; if (def == null || ModelsToIgnore.Contains(def.FilePath)) { chunk.DoodadRefs[i] = int.MinValue; continue; } var uniqueId = def.UniqueId; chunk.DoodadRefs[i] = (int)uniqueId; } for (var i = 0; i < chunk.ObjectRefs.Count; i++) { var objectRef = chunk.ObjectRefs[i]; var def = adt.ObjectDefinitions[objectRef]; if (def == null) { chunk.ObjectRefs[i] = int.MinValue; continue; } var uniqueId = def.UniqueId; chunk.ObjectRefs[i] = (int)uniqueId; } }
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; }
public static void WriteTileInfo(FileStream file, ADT adt) { var writer = new BinaryWriter(file); writer.Write(FileTypeId); writer.Write(adt.IsWMOOnly); WriteWMODefs(writer, adt.ObjectDefinitions); if (adt.IsWMOOnly) return; WriteM2Defs(writer, adt.DoodadDefinitions); WriteQuadTree(writer, adt.QuadTree); writer.Write(adt.TerrainVertices); for (var x = 0; x < TerrainConstants.ChunksPerTileSide; x++) { for (var y = 0; y < TerrainConstants.ChunksPerTileSide; y++) { var chunk = adt.MapChunks[y, x]; // Whether this chunk has a height map WriteChunkInfo(writer, chunk); } } }
private static void PrepareChunkInfo(MpqManager manager, ADT adt) { for (var chunkX = 0; chunkX < TerrainConstants.ChunksPerTileSide; chunkX++) { for (var chunkY = 0; chunkY < TerrainConstants.ChunksPerTileSide; chunkY++) { var chunk = adt.MapChunks[chunkY, chunkX]; foreach (var dRefId in chunk.DoodadRefs) { var dRef = adt.DoodadDefinitions[dRefId]; if (dRef == null) continue; if (ModelsToIgnore.Contains(dRef.FilePath)) continue; if (LoadedM2Ids.Contains(dRef.UniqueId)) continue; M2Model model; if (!WorldObjectExtractor.LoadedM2Models.TryGetValue(dRef.FilePath, out model)) { model = M2ModelParser.Process(manager, dRef.FilePath); WorldObjectExtractor.LoadedM2Models.Add(dRef.FilePath, model); } // This model may have no collision information. If so there is no point saving the data. if (model.BoundingVertices.IsNullOrEmpty()) { // This model has no collision information. We'll ignore it. ModelsToIgnore.Add(dRef.FilePath); WorldObjectExtractor.LoadedM2Models.Remove(dRef.FilePath); } // At this point, we're using the model for collision stuff PrepareM2Info(dRef, model); LoadedM2Ids.Add(dRef.UniqueId); } foreach (var oRefId in chunk.ObjectRefs) { var oRef = adt.ObjectDefinitions[oRefId]; if (oRef == null) continue; LoadWMO(manager, oRef); } PrepareChunk(adt, chunkX, chunkY); } } }
public static ADT ExtractWMOOnly(WDT wdt) { var tileId = new TileIdentifier { MapId = wdt.Entry.Id, MapName = wdt.Name, TileX = 0, TileY = 0 }; var adt = new ADT(tileId); adt.ObjectDefinitions.Capacity = wdt.WmoDefinitions.Count; foreach (var wmoDefinition in wdt.WmoDefinitions) { adt.ObjectDefinitions.Add(wmoDefinition); } adt.ObjectFiles.Capacity = wdt.WmoFiles.Count; foreach (var wmoFile in wdt.WmoFiles) { adt.ObjectFiles.Add(wmoFile); } foreach (var def in adt.ObjectDefinitions) { LoadWMO(wdt.Manager, def); } adt.IsWMOOnly = true; return adt; }
private static void LoadQuadTree(ADT adt) { adt.LoadQuadTree(); }