Add TXTG loading for loaded bfres
This commit is contained in:
parent
a06e1fe8e0
commit
45d20e8f44
@ -20,7 +20,7 @@ using OpenTK;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class BFRES : BFRESWrapper, IFileFormat, ITextureContainer, IExportableModelContainer
|
||||
public class BFRES : BFRESWrapper, IFileFormat, ITextureContainer, IExportableModelContainer, IDisposable
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Resource;
|
||||
|
||||
@ -786,6 +786,11 @@ namespace FirstPlugin
|
||||
}
|
||||
|
||||
public BFRESRenderBase BFRESRender;
|
||||
|
||||
private MeshCodec MeshCodec;
|
||||
|
||||
public void Dispose() { MeshCodec.Dispose(); }
|
||||
|
||||
public void Load(System.IO.Stream stream)
|
||||
{
|
||||
CanSave = true;
|
||||
@ -802,7 +807,10 @@ namespace FirstPlugin
|
||||
BFRESRender.ModelTransform = MarioCostumeEditor.SetTransform(FileName);
|
||||
BFRESRender.ResFileNode = this;
|
||||
|
||||
if (MeshCodec.IsMeshCodec(stream))
|
||||
MeshCodec = new MeshCodec();
|
||||
|
||||
bool isMeshCodec = MeshCodec.IsMeshCodec(stream);
|
||||
if (isMeshCodec)
|
||||
MeshCodec.Prepare();
|
||||
|
||||
if (IsWiiU)
|
||||
@ -826,6 +834,9 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
if (isMeshCodec)
|
||||
MeshCodec.PrepareTexToGo(resFile);
|
||||
|
||||
DrawableContainer.Drawables.Add(BFRESRender);
|
||||
|
||||
var Models = GetModels();
|
||||
|
@ -6,9 +6,9 @@ using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AampLibraryCSharp.IO;
|
||||
using Syroot.NintenTools.NSW.Bfres;
|
||||
using Toolbox.Library;
|
||||
using Toolbox.Library.IO;
|
||||
using ZstdSharp.Unsafe;
|
||||
|
||||
namespace FirstPlugin
|
||||
@ -17,6 +17,8 @@ namespace FirstPlugin
|
||||
{
|
||||
static ResFile ExternalStringBinary;
|
||||
|
||||
List<TXTG> TextureList = new List<TXTG>();
|
||||
|
||||
public static bool IsMeshCodec(Stream stream)
|
||||
{
|
||||
using (var reader = new FileReader(stream, true))
|
||||
@ -55,6 +57,38 @@ namespace FirstPlugin
|
||||
LoadExternalStrings();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var tex in this.TextureList)
|
||||
{
|
||||
tex.Dispose();
|
||||
}
|
||||
TextureList.Clear();
|
||||
}
|
||||
|
||||
public void PrepareTexToGo(ResFile resFile)
|
||||
{
|
||||
var materials = resFile.Models.SelectMany(x => x.Materials);
|
||||
|
||||
List<string> textureList = materials.SelectMany(x => x.TextureRefs).Distinct().ToList();
|
||||
foreach (var tex in textureList)
|
||||
{
|
||||
string path = Path.Combine(Runtime.TotkGamePath, "TexToGo", $"{tex}.txtg");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
//File will be loaded and cached from TXTG load method
|
||||
TextureList.Add((TXTG)STFileLoader.OpenFileFormat(path));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadExternalStrings()
|
||||
{
|
||||
if (ExternalStringBinary != null)
|
||||
|
@ -18,7 +18,7 @@ using VGAudio.Utilities;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class TXTG : STGenericTexture, IFileFormat, ILeaveOpenOnLoad
|
||||
public class TXTG : STGenericTexture, IFileFormat, ILeaveOpenOnLoad, IDisposable
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Image;
|
||||
|
||||
@ -144,7 +144,6 @@ namespace FirstPlugin
|
||||
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
Text = FileName;
|
||||
Tag = this;
|
||||
|
||||
CanReplace = true;
|
||||
@ -152,6 +151,15 @@ namespace FirstPlugin
|
||||
ImageKey = "Texture";
|
||||
SelectedImageKey = "Texture";
|
||||
|
||||
string name = Path.GetFileNameWithoutExtension(FileName);
|
||||
Text = name;
|
||||
|
||||
//cache for loading file
|
||||
if (PluginRuntime.TextureCache.ContainsKey(name))
|
||||
PluginRuntime.TextureCache.Remove(name);
|
||||
|
||||
PluginRuntime.TextureCache.Add(name, this);
|
||||
|
||||
using (var reader = new FileReader(stream, true))
|
||||
{
|
||||
reader.SetByteOrder(false);
|
||||
@ -266,6 +274,12 @@ namespace FirstPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (PluginRuntime.TextureCache.ContainsKey(FileName))
|
||||
PluginRuntime.TextureCache.Remove(FileName);
|
||||
}
|
||||
|
||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||
{
|
||||
var data = ImageList[ArrayLevel][MipLevel];
|
||||
@ -373,6 +387,7 @@ namespace FirstPlugin
|
||||
|
||||
|
||||
{ 0x505, TEX_FORMAT.BC3_UNORM_SRGB },
|
||||
{ 0x602, TEX_FORMAT.BC4_UNORM },
|
||||
{ 0x606, TEX_FORMAT.BC4_UNORM },
|
||||
{ 0x607, TEX_FORMAT.BC4_UNORM },
|
||||
{ 0x702, TEX_FORMAT.BC5_UNORM },
|
||||
|
@ -436,6 +436,22 @@ namespace FirstPlugin
|
||||
return BindBNTX(bntx, tex, shader, activeTex);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var bntx in PluginRuntime.bntxContainers)
|
||||
{
|
||||
if (bntx.Textures.ContainsKey(activeTex))
|
||||
{
|
||||
return BindBNTX(bntx, tex, shader, activeTex);
|
||||
}
|
||||
}
|
||||
if (PluginRuntime.TextureCache.ContainsKey(activeTex))
|
||||
{
|
||||
var t = PluginRuntime.TextureCache[activeTex];
|
||||
if (t.RenderableTex == null || !t.RenderableTex.GLInitialized)
|
||||
t.LoadOpenGLTexture();
|
||||
|
||||
BindGLTexture(tex, shader, t);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -45,6 +45,8 @@ namespace FirstPlugin
|
||||
foreach (TextureData tex in bntx.Textures.Values)
|
||||
listView1.Items.Add(tex.Text, tex.Text, 0);
|
||||
}
|
||||
foreach (var tex in PluginRuntime.TextureCache.Values)
|
||||
listView1.Items.Add(tex.Text, tex.Text, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -90,7 +92,10 @@ namespace FirstPlugin
|
||||
if (bntx.Textures.ContainsKey(TexName))
|
||||
DisplayTexture(bntx.Textures[TexName]);
|
||||
}
|
||||
}
|
||||
|
||||
if (PluginRuntime.TextureCache.ContainsKey(TexName))
|
||||
DisplayTexture(PluginRuntime.TextureCache[TexName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void DisplayTexture(STGenericTexture texData)
|
||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Bfres.Structs;
|
||||
using Toolbox.Library;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
@ -24,6 +25,9 @@ namespace FirstPlugin
|
||||
|
||||
public static bool UseSimpleBfresEditor = false;
|
||||
|
||||
//I really don't recall why I never just used a global texture cache
|
||||
public static Dictionary<string, STGenericTexture> TextureCache = new Dictionary<string, STGenericTexture>();
|
||||
|
||||
public static Dictionary<string, BFLIM> bflimTextures = new Dictionary<string, BFLIM>();
|
||||
public static List<BNTX> bntxContainers = new List<BNTX>();
|
||||
public static List<BFRESGroupNode> ftexContainers = new List<BFRESGroupNode>();
|
||||
|
Loading…
Reference in New Issue
Block a user