public TDX LoadTDXFromZADEntry(ZADEntry entry, ZAD zadFile) { using (MemoryStream stream = new MemoryStream(zadFile.ExtractToBuffer(entry))) { TDX output = TDX.Load(stream, entry.Name); return(output); } }
public override Asset Import(string path) { Texture texture = new Texture { FileName = path }; TDX tdx = TDX.Load(path); texture.SetData(tdx.Name, tdx.Format.ToString(), tdx.MipMaps[0].Width, tdx.MipMaps[0].Height, tdx.MipMaps[0].Data); texture.SupportingDocuments["Source"] = tdx; return(texture); }
public override Asset Import(string path) { Texture texture = new Texture(); texture.FileName = path; if (string.Compare(Path.GetExtension(path), ".tdx", true) == 0) { TDX tdx = TDX.Load(path); texture.SetData(tdx.Name, tdx.Format.ToString(), tdx.MipMaps[0].Width, tdx.MipMaps[0].Height, tdx.MipMaps[0].Data); texture.SupportingDocuments["Source"] = tdx; } else { texture = (Texture)(new IMGImporter()).Import(path); } return(texture); }
void ReplaceSelectedTexture_Click(object sender, EventArgs e) { var textureToReplace = (crVTMapEntry)TextureList.SelectedItem; OpenFileDialog dialog = new OpenFileDialog(); dialog.InitialDirectory = Properties.Settings.Default.LastImportDirectory; dialog.Title = "Export Texture"; dialog.Filter = "PNG Image (*.PNG)|*.png|JPEG Image (*.JPG, *.JPEG)|*.jpg;*.jpeg|BMP Image (*.BMP)|*.bmp|TIFF Image (*.TIF, *.TIFF)|*.tif;*.tiff|TGA Image (*.TGA)|*.tga|TDX Texture (*.TDX)|*.tdx"; dialog.FileName = Path.GetFileName(textureToReplace.FileName); var result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.OK && Directory.Exists(Path.GetDirectoryName(dialog.FileName))) { Properties.Settings.Default.LastImportDirectory = Path.GetDirectoryName(dialog.FileName); Properties.Settings.Default.Save(); var vtPage = (crVTPage)PageNumSelect.SelectedItem; var fileType = Path.GetExtension(dialog.FileName).ToUpper(); ImageFormat imgFormat = ImageFormat.Png; Bitmap image = null; if (fileType == ".TGA") { image = Paloma.TargaImage.LoadTargaImage(dialog.FileName); } else if (fileType == ".TDX") { image = TDX.Load(dialog.FileName).Decompress(); } else { image = (Bitmap)Bitmap.FromFile(dialog.FileName); } //if (image.Width != textureToReplace.GetWidth(vtPage.PageNum) || image.Height != textureToReplace.GetHeight(vtPage.PageNum)) MessageBox.Show("Error: Image dimensions need to match the original texture!", "Texture Size Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error); //else { List <crVTPage> pages = null; if (PageType.SelectedItem == "Diffuse") { pages = diffusePages; } else if (PageType.SelectedItem == "Specular") { pages = specularPages; } else if (PageType.SelectedItem == "Normal") { pages = normalPages; } foreach (var page in pages) { if (page.PageNum == 0) { continue; } int targetWidth = textureToReplace.GetWidth(page.PageNum); int targetHeight = textureToReplace.GetHeight(page.PageNum); Bitmap mipimage = null; if (image.Width != targetWidth || image.Height != targetHeight) { mipimage = new Bitmap(targetWidth, targetHeight); var srcRect = new RectangleF(0, 0, image.Width, image.Height); var destRect = new RectangleF(0, 0, targetWidth, targetHeight); Graphics grfx = Graphics.FromImage(mipimage); grfx.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; grfx.DrawImage(image, destRect, srcRect, GraphicsUnit.Pixel); } else { mipimage = image; } var tiles = page.ImportTexture(mipimage, textureToReplace); foreach (var tile in tiles) { ZAD currentZAD = ZAD.Load(tile.ZADFile); ZADEntry tileEntry = currentZAD.Contents.Find(possibleEntry => possibleEntry.Name == tile.ZADEntryLocation); currentZAD.ReplaceEntryFromBuffer(tileEntry, tile.Texture.SaveToBuffer()); } /*foreach(var tile in tiles) * { * using (ZipArchive zip = ZipFile.Open(tile.ZADFile, ZipArchiveMode.Update)) * { * * var zipentry = zip.GetEntry(tile.ZADEntryLocation); * zipentry.Delete(); * zipentry = zip.CreateEntry(tile.ZADEntryLocation, CompressionLevel.NoCompression); * using (Stream stream = zipentry.Open()) * { * tile.Texture.Save(stream); * } * * } * }*/ } } } }