Some platform swizzle fixes and preview textures for bmd

This commit is contained in:
KillzXGaming 2019-08-01 18:11:56 -04:00
parent f4e4afa2f7
commit a9b92e42e2
6 changed files with 69 additions and 21 deletions

View file

@ -18,8 +18,10 @@ using OpenTK;
namespace FirstPlugin
{
public class BMD : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer
public class BMD : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer, ITextureIconLoader
{
public List<STGenericTexture> IconTextureList { get; set; }
public FileType FileType { get; set; } = FileType.Layout;
public bool CanSave { get; set; }
@ -115,6 +117,7 @@ namespace FirstPlugin
DrawableContainer.Drawables.Add(Skeleton);
Textures = new Dictionary<string, STGenericTexture>();
IconTextureList = new List<STGenericTexture>();
BMD_Renderer.TextureContainers.Add(this);
@ -254,6 +257,7 @@ namespace FirstPlugin
var texWrapper = new BMDTextureWrapper(BMDFile.Textures.Textures[i]);
TextureFolder.Nodes.Add(texWrapper);
Renderer.TextureList.Add(texWrapper);
IconTextureList.Add(texWrapper);
}
}

View file

@ -23,6 +23,8 @@ namespace FirstPlugin
{
public class BNTX : TreeNodeFile, IFileFormat, IContextMenuNode
{
public List<STGenericTexture> IconTextureList { get; set; }
public FileType FileType { get; set; } = FileType.Image;
public bool CanSave { get; set; }
@ -482,6 +484,7 @@ namespace FirstPlugin
public void LoadFile(Stream stream, string Name = "")
{
Textures = new Dictionary<string, TextureData>(StringComparer.InvariantCultureIgnoreCase);
IconTextureList = new List<STGenericTexture>();
BinaryTexFile = new BntxFile(stream);
Text = BinaryTexFile.Name;

View file

@ -102,9 +102,13 @@ namespace Toolbox.Library
imgList.Images.Add(image);
}
private Thread Thread;
public void ReloadTextureIcons()
{
Thread Thread = new Thread((ThreadStart)(() =>
if (Thread != null && Thread.IsAlive)
Thread.Abort();
Thread = new Thread((ThreadStart)(() =>
{
foreach (var textureIconList in TextureIcons)
{
@ -123,18 +127,54 @@ namespace Toolbox.Library
public void ReloadTextureIcons(ITextureIconLoader textureIconList)
{
Thread Thread = new Thread((ThreadStart)(() =>
if (Thread != null && Thread.IsAlive)
Thread.Abort();
this.BeginUpdate();
Thread = new Thread((ThreadStart)(() =>
{
foreach (TreeNode node in textureIconList.IconTextureList)
node.ImageKey = "Texture";
this.Invoke((MethodInvoker)delegate
{
{
this.Refresh();
}
});
foreach (TreeNode node in textureIconList.IconTextureList)
{
if (node is STGenericTexture)
{
var image = ((STGenericTexture)node).GetBitmap();
AddImageOnThread(image, node);
try
{
var image = ((STGenericTexture)node).GetBitmap();
AddImageOnThread(image, node);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
if (this.InvokeRequired)
{
this.Invoke((MethodInvoker)delegate
{
{
this.EndUpdate();
this.Refresh();
}
});
}
else
this.EndUpdate();
}));
Thread.Start();
}
public void AddImageOnThread(Image image, TreeNode node)
@ -149,7 +189,6 @@ namespace Toolbox.Library
this.ImageList.Images.Add(image);
var dummy = this.ImageList.Handle;
this.Refresh();
image.Dispose();
});

View file

@ -520,25 +520,27 @@ namespace Toolbox.Library
imageData = CTR_3DS.DecodeBlock(data, (int)Width, (int)Height, Format);
DontSwapRG = true;
}
if (PlatformSwizzle == PlatformSwizzle.Platform_Gamecube)
else if (PlatformSwizzle == PlatformSwizzle.Platform_Gamecube)
imageData = Decode_Gamecube.DecodeData(data, paletteData, Width, Height, Format, PaletteFormat);
if (Format == TEX_FORMAT.R32G8X24_FLOAT)
imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, DDS.DXGI_FORMAT.DXGI_FORMAT_R32G8X24_TYPELESS);
if (Format == TEX_FORMAT.BC5_SNORM)
imageData = DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true, true);
if (IsCompressed(Format))
imageData = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format);
else
{
if (IsAtscFormat(Format))
imageData = ASTCDecoder.DecodeToRGBA8888(data, (int)GetBlockWidth(Format), (int)GetBlockHeight(Format), 1, (int)Width, (int)Height, 1);
else
imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format);
if (Format == TEX_FORMAT.R32G8X24_FLOAT)
imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, DDS.DXGI_FORMAT.DXGI_FORMAT_R32G8X24_TYPELESS);
// imageData = RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format);
if (Format == TEX_FORMAT.BC5_SNORM)
imageData = DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true, true);
if (IsCompressed(Format))
imageData = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format);
else
{
if (IsAtscFormat(Format))
imageData = ASTCDecoder.DecodeToRGBA8888(data, (int)GetBlockWidth(Format), (int)GetBlockHeight(Format), 1, (int)Width, (int)Height, 1);
else
imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format);
// imageData = RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format);
}
}
if (parameters.DontSwapRG || DontSwapRG)