Add dialog for replacing unswizzled images for nutexb
This commit is contained in:
parent
8cbc45f3a1
commit
7ca392bdfe
@ -264,36 +264,84 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
public override void Replace(string FileName)
|
public override void Replace(string FileName)
|
||||||
{
|
{
|
||||||
var tex = new TextureData();
|
if (IsSwizzled)
|
||||||
tex.Replace(FileName, MipCount, 0, Format);
|
{
|
||||||
|
var tex = new TextureData();
|
||||||
|
tex.Replace(FileName, MipCount, 0, Format);
|
||||||
|
|
||||||
//If it's null, the operation is cancelled
|
//If it's null, the operation is cancelled
|
||||||
if (tex.Texture == null)
|
if (tex.Texture == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<byte[]> data = new List<byte[]>();
|
List<byte[]> data = new List<byte[]>();
|
||||||
foreach (var array in tex.Texture.TextureData)
|
foreach (var array in tex.Texture.TextureData)
|
||||||
data.Add(array[0]);
|
data.Add(array[0]);
|
||||||
|
|
||||||
var output = Utils.CombineByteArray(data.ToArray());
|
var output = Utils.CombineByteArray(data.ToArray());
|
||||||
|
|
||||||
Width = tex.Texture.Width;
|
Width = tex.Texture.Width;
|
||||||
Height = tex.Texture.Height;
|
Height = tex.Texture.Height;
|
||||||
MipCount = tex.Texture.MipCount;
|
MipCount = tex.Texture.MipCount;
|
||||||
// ArrayCount = tex.Texture.ArrayLength;
|
// ArrayCount = tex.Texture.ArrayLength;
|
||||||
// Depth = tex.Texture.Depth;
|
// Depth = tex.Texture.Depth;
|
||||||
|
|
||||||
Format = tex.Format;
|
Format = tex.Format;
|
||||||
NutFormat = ConvertGenericToNutFormat(tex.Format);
|
NutFormat = ConvertGenericToNutFormat(tex.Format);
|
||||||
|
|
||||||
mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);
|
mipSizes = TegraX1Swizzle.GenerateMipSizes(tex.Format, tex.Width, tex.Height, tex.Depth, tex.ArrayCount, tex.MipCount, (uint)ImageData.Length);
|
||||||
|
|
||||||
ImageData = SetImageData(output);
|
ImageData = SetImageData(output);
|
||||||
|
|
||||||
|
data.Clear();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GenericTextureImporterList importer = new GenericTextureImporterList(SupportedFormats);
|
||||||
|
GenericTextureImporterSettings settings = new GenericTextureImporterSettings();
|
||||||
|
|
||||||
|
if (Utils.GetExtension(FileName) == ".dds" ||
|
||||||
|
Utils.GetExtension(FileName) == ".dds2")
|
||||||
|
{
|
||||||
|
settings.LoadDDS(FileName);
|
||||||
|
importer.LoadSettings(new List<GenericTextureImporterSettings>() { settings, });
|
||||||
|
ApplySettings(settings);
|
||||||
|
UpdateEditor();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settings.LoadBitMap(FileName);
|
||||||
|
importer.LoadSettings(new List<GenericTextureImporterSettings>() { settings, });
|
||||||
|
|
||||||
|
if (importer.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (settings.GenerateMipmaps && !settings.IsFinishedCompressing)
|
||||||
|
{
|
||||||
|
settings.DataBlockOutput.Clear();
|
||||||
|
settings.DataBlockOutput.Add(settings.GenerateMips(importer.CompressionMode, importer.MultiThreading));
|
||||||
|
}
|
||||||
|
|
||||||
|
ApplySettings(settings);
|
||||||
|
UpdateEditor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data.Clear();
|
|
||||||
UpdateEditor();
|
UpdateEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ApplySettings(GenericTextureImporterSettings settings)
|
||||||
|
{
|
||||||
|
//Combine all arrays
|
||||||
|
this.ImageData = Utils.CombineByteArray(settings.DataBlockOutput.ToArray());
|
||||||
|
this.Width = settings.TexWidth;
|
||||||
|
this.Height = settings.TexHeight;
|
||||||
|
this.Format = settings.Format;
|
||||||
|
this.MipCount = settings.MipCount;
|
||||||
|
this.Depth = settings.Depth;
|
||||||
|
this.ArrayCount = (uint)settings.DataBlockOutput.Count;
|
||||||
|
NutFormat = ConvertGenericToNutFormat(this.Format);
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] SetImageData(byte[] output)
|
private byte[] SetImageData(byte[] output)
|
||||||
{
|
{
|
||||||
if (output.Length < ImageData.Length && LimitFileSize)
|
if (output.Length < ImageData.Length && LimitFileSize)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user