Skip to content

Commit

Permalink
Automatically re-add placeholder textures on save if user deletes the…
Browse files Browse the repository at this point in the history
…m to prevent errors in game.
  • Loading branch information
KillzXGaming committed May 8, 2022
1 parent 47c62b0 commit e72a128
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Plugins/CafeLibrary/Bfres/Editing/Nodes/ModelWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e72a128

Please sign in to comment.