From e72a1283fc4f6fbc061dfc0bbc471becd009af91 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Sun, 8 May 2022 10:32:16 -0400 Subject: [PATCH] Automatically re-add placeholder textures on save if user deletes them to prevent errors in game. --- .../Bfres/Editing/Nodes/ModelWrapper.cs | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Plugins/CafeLibrary/Bfres/Editing/Nodes/ModelWrapper.cs b/Plugins/CafeLibrary/Bfres/Editing/Nodes/ModelWrapper.cs index 5e2a9fa..d03f089 100644 --- a/Plugins/CafeLibrary/Bfres/Editing/Nodes/ModelWrapper.cs +++ b/Plugins/CafeLibrary/Bfres/Editing/Nodes/ModelWrapper.cs @@ -59,7 +59,9 @@ public void OnSave() foreach (FMDL fmdl in Models) { ResFile.Models.Add(fmdl.Name, fmdl.Model); - + foreach (FMAT mat in fmdl.Materials) { + mat.OnSave(); + } foreach (FSHP fshp in fmdl.Meshes) { fshp.Shape.VertexBufferIndex = (ushort)fmdl.Model.VertexBuffers.IndexOf(fshp.VertexBuffer); if (!fmdl.Model.Materials.ContainsValue(fshp.Material.Material)) @@ -817,6 +819,37 @@ public FMAT(BFRES bfres, FMDL fmdl, ResFile resFile, Material mat) ReloadMaterial(mat); } + public void OnSave() + { + //Check for present textures + if (BfresWrapper.Renderer.Textures.Count > 0) + { + //Check for placeholders missing incase the user deletes them + for (int i = 0; i < TextureMaps.Count; i++) + { + string textureName = TextureMaps[i].Name; + //Texture is present so skip + if (BfresWrapper.Renderer.Textures.ContainsKey(textureName)) + continue; + + //Check for what texture type to add as a placeholder + switch (textureName) + { + case "Basic_Alb": + case "Basic_Spm": + case "Basic_Emm": + case "Basic_Trm": + case "Basic_BC1_Nrm": + case "Basic_Nrm": + case "Basic_Bake_st0": + case "Basic_Bake_st1": + AddPlaceholderTextures(Material, Samplers[i], i); + break; + } + } + } + } + public void TryInsertParamAnimKey(ShaderParam param) { BfresWrapper.TryInsertParamKey(Material.Name, param); }