diff --git a/BrawlboxHelper/Syroot.NintenTools.Bfres.dll b/BrawlboxHelper/Syroot.NintenTools.Bfres.dll index e6997c45..6a113d72 100644 Binary files a/BrawlboxHelper/Syroot.NintenTools.Bfres.dll and b/BrawlboxHelper/Syroot.NintenTools.Bfres.dll differ diff --git a/BrawlboxHelper/Syroot.NintenTools.NSW.Bfres.dll b/BrawlboxHelper/Syroot.NintenTools.NSW.Bfres.dll index 7d7717bd..725ad16f 100644 Binary files a/BrawlboxHelper/Syroot.NintenTools.NSW.Bfres.dll and b/BrawlboxHelper/Syroot.NintenTools.NSW.Bfres.dll differ diff --git a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs index d64800a6..e45a6894 100644 --- a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs +++ b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs @@ -1230,10 +1230,10 @@ namespace Bfres.Structs float xxMax = GetExtent(max.X, min.X); float yyMax = GetExtent(max.Y, min.Y); float zzMax = GetExtent(max.Z, min.Z); - float radius = CalculateBoundingRadius(min, max); - Vector3 extend = new Vector3(xxMax, yyMax, zzMax); + float radius = (float)(center.Length + extend.Length); + return new BoundingBox() { Radius = radius, Center = center, Extend = extend }; } diff --git a/File_Format_Library/FileFormats/Texture/XTX.cs b/File_Format_Library/FileFormats/Texture/XTX.cs index 47429192..6db37e0b 100644 --- a/File_Format_Library/FileFormats/Texture/XTX.cs +++ b/File_Format_Library/FileFormats/Texture/XTX.cs @@ -32,7 +32,7 @@ namespace FirstPlugin } } - public bool DisplayIcons => true; + public bool DisplayIcons => false; //Astc decoding is slow and the UI has loading issues atm public List TextureList { @@ -65,12 +65,18 @@ namespace FirstPlugin string name = Path.GetFileNameWithoutExtension(FileName); TextureInfos[i].Text = TextureInfos.Count == 1 ? name : $"{name}_image{i}"; } - - ContextMenuStrip = new STContextMenuStrip(); - ContextMenuStrip.Items.Add(new ToolStripMenuItem("Save", null, SaveAction, Keys.Control | Keys.S)); } - private void SaveAction(object sender, EventArgs args) + public ToolStripItem[] GetContextMenuItems() + { + return new ToolStripItem[] + { + new ToolStripMenuItem("Save", null, Save, Keys.Control | Keys.S), + new ToolStripMenuItem("Export All", null, ExportAllAction, Keys.Control | Keys.E), + }; + } + + private void Save(object sender, EventArgs args) { SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = "xtx"; @@ -83,6 +89,45 @@ namespace FirstPlugin } } + protected void ExportAllAction(object sender, EventArgs e) + { + if (Nodes.Count <= 0) + return; + + string formats = FileFilters.XTX; + + string[] forms = formats.Split('|'); + + List Formats = new List(); + + for (int i = 0; i < forms.Length; i++) + { + if (i > 1 || i == (forms.Length - 1)) //Skip lines with all extensions + { + if (!forms[i].StartsWith("*")) + Formats.Add(forms[i]); + } + } + + FolderSelectDialog sfd = new FolderSelectDialog(); + if (sfd.ShowDialog() == DialogResult.OK) + { + string folderPath = sfd.SelectedPath; + + BatchFormatExport form = new BatchFormatExport(Formats); + if (form.ShowDialog() == DialogResult.OK) + { + string extension = form.GetSelectedExtension(); + extension.Replace(" ", string.Empty); + + foreach (STGenericTexture node in Nodes) + { + ((STGenericTexture)node).Export($"{folderPath}\\{node.Text}{extension}"); + } + } + } + } + public void Unload() { @@ -326,53 +371,6 @@ namespace FirstPlugin } } - public virtual ToolStripItem[] GetContextMenuItems() - { - List Items = new List(); - Items.Add(new ToolStripMenuItem("Export All", null, ExportAllAction, Keys.Control | Keys.E)); - return Items.ToArray(); - } - - private void ExportAllAction(object sender, EventArgs args) - { - ExportAll(); - } - - public virtual void ExportAll() - { - List Formats = new List(); - Formats.Add("Microsoft DDS (.dds)"); - Formats.Add("Portable Graphics Network (.png)"); - Formats.Add("Joint Photographic Experts Group (.jpg)"); - Formats.Add("Bitmap Image (.bmp)"); - Formats.Add("Tagged Image File Format (.tiff)"); - - FolderSelectDialog sfd = new FolderSelectDialog(); - - if (sfd.ShowDialog() == DialogResult.OK) - { - string folderPath = sfd.SelectedPath; - - BatchFormatExport form = new BatchFormatExport(Formats); - if (form.ShowDialog() == DialogResult.OK) - { - foreach (STGenericTexture tex in Nodes) - { - if (form.Index == 0) - tex.SaveDDS(folderPath + '\\' + tex.Text + ".dds"); - else if (form.Index == 1) - tex.SaveBitMap(folderPath + '\\' + tex.Text + ".png"); - else if (form.Index == 2) - tex.SaveBitMap(folderPath + '\\' + tex.Text + ".jpg"); - else if (form.Index == 3) - tex.SaveBitMap(folderPath + '\\' + tex.Text + ".bmp"); - else if (form.Index == 4) - tex.SaveBitMap(folderPath + '\\' + tex.Text + ".tiff"); - } - } - } - } - public class BlockHeader { public uint BlockSize { get; set; } @@ -479,11 +477,22 @@ namespace FirstPlugin public uint[] MipOffsets { get; set; } public byte[] ImageData; + public uint TextureLayout1; + public uint TextureLayout2; + + public uint Boolean; + public override string ExportFilter => FileFilters.XTX; public override string ReplaceFilter => FileFilters.XTX; private byte[] unknownData; + public TextureInfo() + { + CanExport = true; + CanReplace = true; + } + public void Read(FileReader reader) { DataSize = reader.ReadUInt64(); @@ -495,15 +504,13 @@ namespace FirstPlugin XTXFormat = reader.ReadEnum(true); MipCount = reader.ReadUInt32(); SliceSize = reader.ReadUInt32(); - MipOffsets = reader.ReadUInt32s((int)MipCount); - unknownData = reader.ReadBytes(0x38); + MipOffsets = reader.ReadUInt32s(17); + TextureLayout1 = reader.ReadUInt32(); + TextureLayout2 = reader.ReadUInt32(); + Boolean = reader.ReadUInt32(); Format = ConvertFormat(XTXFormat); ArrayCount = 1; - - ContextMenuStrip = new STContextMenuStrip(); - ContextMenuStrip.Items.Add(new ToolStripMenuItem("Export", null, ExportAction, Keys.Control | Keys.E)); - ContextMenuStrip.Items.Add(new ToolStripMenuItem("Replace", null, ReplaceAction, Keys.Control | Keys.R)); } public byte[] Write() @@ -535,7 +542,6 @@ namespace FirstPlugin public override void Replace(string FileName) { - var bntxFile = new BNTX(); var tex = new TextureData(); tex.Replace(FileName, MipCount, 0, Format); @@ -551,6 +557,8 @@ namespace FirstPlugin Width = tex.Texture.Width; Height = tex.Texture.Height; MipCount = tex.Texture.MipCount; + TextureLayout1 = tex.Texture.textureLayout; + TextureLayout2 = tex.Texture.textureLayout2; Format = tex.Format; XTXFormat = ConvertFromGenericFormat(tex.Format); @@ -733,7 +741,9 @@ namespace FirstPlugin public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0) { - return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, DepthLevel, (int)Target); + var blockHeightLog2 = TextureLayout1 & 7; + + return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, DepthLevel, blockHeightLog2, (int)Target); } } } diff --git a/File_Format_Library/NodeWrappers/FileFilters.cs b/File_Format_Library/NodeWrappers/FileFilters.cs index 75d0b22d..e68e2e91 100644 --- a/File_Format_Library/NodeWrappers/FileFilters.cs +++ b/File_Format_Library/NodeWrappers/FileFilters.cs @@ -47,7 +47,7 @@ namespace FirstPlugin public static string REV_TEX = GetFilter(".png", ".bmp", ".tga", ".jpg", ".tiff", ".tif", ".gif"); public static string NUTEXB = GetFilter(".dds",".png", ".bmp", ".tga", ".jpg", ".tiff", ".tif", ".gif"); - public static string XTX = GetFilter(".dds", ".png", ".bmp", ".tga", ".jpg", ".tiff", ".tif", ".gif"); + public static string XTX = GetFilter(".dds", ".astc", ".png", ".bmp", ".tga", ".jpg", ".tiff", ".tif", ".gif"); public static string GetFilter(Type type, object CheckAnimEffect = null, bool IsExporting = false) {