Add original texture swizzle pattern to importer setting to prevent swizzle issues

This commit is contained in:
KillzXGaming 2019-06-30 19:46:32 -04:00
parent 44dea5fefd
commit a4fb55b5e7
8 changed files with 18 additions and 7 deletions

Binary file not shown.

View file

@ -193,7 +193,7 @@ namespace Bfres.Structs
if (texture != null && texture.MipCount == 1) if (texture != null && texture.MipCount == 1)
ReplaceTexture(FileName, Format, texture.MipCount); ReplaceTexture(FileName, Format, texture.MipCount);
else else
ReplaceTexture(FileName, Format); ReplaceTexture(FileName, Format, 0, null, false, false, false, texture.SwizzlePattern);
} }
public void ReplaceTexture(string FileName, TEX_FORMAT DefaultFormat = TEX_FORMAT.UNKNOWN, uint MipMapCount = 0, TEX_FORMAT[] SupportedFormats = null, public void ReplaceTexture(string FileName, TEX_FORMAT DefaultFormat = TEX_FORMAT.UNKNOWN, uint MipMapCount = 0, TEX_FORMAT[] SupportedFormats = null,

View file

@ -621,21 +621,22 @@ namespace Switch_Toolbox.Library
blkHeight = 1; blkHeight = 1;
} }
byte[] data = new byte[tex.data.Length];
Array.Copy(tex.data, 0, data, 0, tex.data.Length);
var surfInfo = getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, tex.depth, (uint)tex.dim, (uint)tex.tileMode, (uint)tex.aa, 0); var surfInfo = getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, tex.depth, (uint)tex.dim, (uint)tex.tileMode, (uint)tex.aa, 0);
uint bpp = DIV_ROUND_UP(surfInfo.bpp, 8); uint bpp = DIV_ROUND_UP(surfInfo.bpp, 8);
if (tex.numArray == 0) if (tex.numArray == 0)
tex.numArray = 1; tex.numArray = 1;
byte[] data = new byte[tex.data.Length];
byte[] mipdata = new byte[tex.mipData.Length];
uint mipCount = tex.numMips; uint mipCount = tex.numMips;
if (tex.mipData == null || tex.mipData.Length <= 0) if (tex.mipData == null || tex.mipData.Length <= 0)
mipCount = 1; mipCount = 1;
int dataOffset = 0; int dataOffset = 0;
int mipDataOffset = 0; int mipDataOffset = 0;
int mipSpliceSize = 0;
for (int arrayLevel = 0; arrayLevel < tex.depth; arrayLevel++) for (int arrayLevel = 0; arrayLevel < tex.depth; arrayLevel++)
{ {
@ -658,17 +659,27 @@ namespace Switch_Toolbox.Library
mipOffset = (tex.mipOffset[mipLevel - 1]); mipOffset = (tex.mipOffset[mipLevel - 1]);
if (mipLevel == 1) if (mipLevel == 1)
{
mipOffset -= (uint)surfInfo.surfSize; mipOffset -= (uint)surfInfo.surfSize;
mipOffset += (uint)mipDataOffset;
mipSpliceSize += (int)mipOffset;
}
Console.WriteLine("mipOffset " + mipOffset);
if (GetLevel) if (GetLevel)
{ {
surfInfo = getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, tex.depth, (uint)tex.dim, (uint)tex.tileMode, (uint)tex.aa, mipLevel); surfInfo = getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, tex.depth, (uint)tex.dim, (uint)tex.tileMode, (uint)tex.aa, mipLevel);
data = new byte[surfInfo.sliceSize];
Array.Copy(tex.mipData, (uint)mipDataOffset + mipOffset, data, 0, surfInfo.sliceSize); Array.Copy(tex.mipData, 0, mipdata, 0, tex.mipData.Length);
Array.Copy(tex.mipData, (int)mipOffset, mipdata, 0, (int)surfInfo.sliceSize);
data = mipdata;
} }
} }
else if (GetLevel) else if (GetLevel)
{
Array.Copy(tex.data, 0, data, 0, tex.data.Length);
Array.Copy(tex.data, (uint)dataOffset, data, 0, size); Array.Copy(tex.data, (uint)dataOffset, data, 0, size);
}
if (GetLevel) if (GetLevel)
{ {
@ -682,7 +693,7 @@ namespace Switch_Toolbox.Library
} }
dataOffset += (int)surfInfo.sliceSize; dataOffset += (int)surfInfo.sliceSize;
mipDataOffset += (int)surfInfo.sliceSize; mipDataOffset += mipSpliceSize;
} }
return null; return null;
} }