Skip to content

Commit

Permalink
Combine UVs only if the right attribute is used after settings apply
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Oct 17, 2024
1 parent ff65ae6 commit bb51ba6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Plugins/CafeLibrary/Bfres/Editing/Nodes/ModelWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ public void ImportModel(string filePath, bool replacing = false, Action onImport
if (!ok)
return;

modelDlg.OnApply(materials);
//Import the bfres model data
Model = BfresModelImporter.ImportModel(ResFile, Model, ioscene, filePath, settings);
ImportModel(Model, materials, settings);
Expand All @@ -507,6 +508,7 @@ public void ImportModel(string filePath, bool replacing = false, Action onImport
}
else
{
modelDlg.OnApply(materials);
//Import the bfres model data
Model = BfresModelImporter.ImportModel(ResFile, Model, ioscene, filePath, settings);
ImportModel(Model, materials, settings);
Expand Down
24 changes: 19 additions & 5 deletions Plugins/CafeLibrary/Bfres/Imgui/ModelImportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using MapStudio.UI;
using IONET.Core;
using Toolbox.Core;
using BfresLibrary;

namespace CafeLibrary
{
Expand All @@ -25,15 +26,29 @@ public class ModelImportDialog : UIFramework.Window

}

public void OnApply(List<Material> materials)
{
foreach (var mesh in this.Settings.Meshes)
{
//Map original by default
var mat = materials.FirstOrDefault(x => x.Name == mesh.MaterialName);
//Map to imported instance if needed
if (mesh.MaterialInstance != null)
mat = mesh.MaterialInstance;

if (mat != null) {
//Use combined UVs if used by the material
mesh.CombineUVs = mat.ShaderAssign != null &&
mat.ShaderAssign.AttribAssigns.ContainsValue("_g3d_02_u0_u1");
}
}
}

public void Setup(FMDL fmdl, IOScene scene, ModelImportSettings settings)
{
Settings = settings;
PresetWindow.LoadPresets(fmdl.ResFile.IsPlatformSwitch);

//Check for combined
var combineUVs = fmdl.Model.Materials.Values.Any(x => x.ShaderAssign != null &&
x.ShaderAssign.AttribAssigns.ContainsValue("_g3d_02_u0_u1"));

string DefaultPreset = "";
bool isCourse = fmdl.ResFile.Name == "course_model.szs";
bool isSwitch = fmdl.ResFile.IsPlatformSwitch;
Expand All @@ -53,7 +68,6 @@ public void Setup(FMDL fmdl, IOScene scene, ModelImportSettings settings)
var meshSettings = new ModelImportSettings.MeshSettings();
meshSettings.MeshData = mesh;
meshSettings.Name = mesh.Name;
meshSettings.CombineUVs = combineUVs;
meshSettings.MaterialName = "";
meshSettings.SkinCount = mesh.Vertices.Max(x => x.Envelope.Weights.Count);
meshSettings.Normal.Enable = mesh.HasNormals;
Expand Down

0 comments on commit bb51ba6

Please sign in to comment.