diff --git a/FModel/Views/Snooper/Material.cs b/FModel/Views/Snooper/Material.cs index 37972ff8..f2a5ba57 100644 --- a/FModel/Views/Snooper/Material.cs +++ b/FModel/Views/Snooper/Material.cs @@ -317,10 +317,10 @@ public class Material : IDisposable return ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(ImGuiMouseButton.Left); } - public Vector2[] ImGuiTextureViewer(Dictionary icons, Model model) + public Vector2[] ImGuiTextureInspector(Texture fallback) { - var texture = GetSelectedTexture() ?? icons["noimage"]; - if (ImGui.BeginTable("texture_viewer_table", 2, ImGuiTableFlags.SizingStretchProp)) + var texture = GetSelectedTexture() ?? fallback; + if (ImGui.BeginTable("texture_inspector", 2, ImGuiTableFlags.SizingStretchProp)) { SnimGui.Layout("Type");ImGui.Text($" : ({texture.Format}) {texture.Name}"); SnimGui.TooltipCopy("(?) Click to Copy Path", texture.Path); diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index c4a5b160..bd96fe45 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Numerics; using System.Threading; using System.Windows; @@ -258,27 +259,50 @@ public class Renderer : IDisposable else if (m.TryConvert(out var mesh)) { model = new Model(m, mesh, t); - if (actor.TryGetAllValues(out FPackageIndex[] textureData, "TextureData")) + if (actor.TryGetValue(out FPackageIndex baseMaterial, "BaseMaterial") && + actor.TryGetAllValues(out FPackageIndex[] textureData, "TextureData")) { - for (int j = 0; j < textureData.Length; j++) + var material = model.Materials.FirstOrDefault(x => x.Name == baseMaterial.Name); + if (material is { IsUsed: true }) { - if (!model.Materials[model.Sections[j].MaterialIndex].IsUsed || - textureData[j].Load() is not { } textureDataIdx) - continue; + for (int j = 0; j < textureData.Length; j++) + { + var diffuse_key = j switch + { + 0 => "Diffuse", + > 0 => $"Diffuse_Texture_{j + 1}", + _ => CMaterialParams2.FallbackDiffuse + }; + var normal_key = j switch + { + 0 => "Normals", + > 0 => $"Normals_Texture_{j + 1}", + _ => CMaterialParams2.FallbackNormals + }; + var specularmasks_key = j switch + { + 0 => "SpecularMasks", + > 0 => $"SpecularMasks_{j + 1}", + _ => CMaterialParams2.FallbackNormals + }; - if (textureDataIdx.TryGetValue(out FPackageIndex overrideMaterial, "OverrideMaterial") && - overrideMaterial.TryLoad(out var material) && material is UMaterialInterface unrealMaterial) - model.Materials[model.Sections[j].MaterialIndex].SwapMaterial(unrealMaterial); + if (textureData[j]?.Load() is not { } textureDataIdx) + continue; - if (textureDataIdx.TryGetValue(out FPackageIndex diffuse, "Diffuse") && - diffuse.Load() is UTexture2D diffuseTexture) - model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures["Diffuse"] = diffuseTexture; - if (textureDataIdx.TryGetValue(out FPackageIndex normal, "Normal") && - normal.Load() is UTexture2D normalTexture) - model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures["Normals"] = normalTexture; - if (textureDataIdx.TryGetValue(out FPackageIndex specular, "Specular") && - specular.Load() is UTexture2D specularTexture) - model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures["SpecularMasks"] = specularTexture; + if (textureDataIdx.TryGetValue(out FPackageIndex overrideMaterial, "OverrideMaterial") && + overrideMaterial.TryLoad(out var oMaterial) && oMaterial is UMaterialInterface oUnrealMaterial) + material.SwapMaterial(oUnrealMaterial); + + if (textureDataIdx.TryGetValue(out FPackageIndex diffuse, "Diffuse") && + diffuse.Load() is UTexture2D diffuseTexture) + material.Parameters.Textures[diffuse_key] = diffuseTexture; + if (textureDataIdx.TryGetValue(out FPackageIndex normal, "Normal") && + normal.Load() is UTexture2D normalTexture) + material.Parameters.Textures[normal_key] = normalTexture; + if (textureDataIdx.TryGetValue(out FPackageIndex specular, "Specular") && + specular.Load() is UTexture2D specularTexture) + material.Parameters.Textures[specularmasks_key] = specularTexture; + } } } if (staticMeshComp.TryGetValue(out FPackageIndex[] overrideMaterials, "OverrideMaterials")) diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs index 02b89c18..6237582a 100644 --- a/FModel/Views/Snooper/SnimGui.cs +++ b/FModel/Views/Snooper/SnimGui.cs @@ -44,8 +44,8 @@ public class SnimGui private readonly Save _saver = new (); private readonly string _renderer; private readonly string _version; - private bool _openTextureViewer; - private bool _overlayUvOverTexture; + private bool _ti_open; + private bool _ti_overlayUv; private bool _viewportFocus; private readonly Vector4 _accentColor = new (0.125f, 0.42f, 0.831f, 1.0f); @@ -78,7 +78,7 @@ public class SnimGui Draw3DViewport(s); DrawNavbar(); - if (_openTextureViewer) DrawTextureViewer(s); + if (_ti_open) DrawTextureInspector(s); Controller.Render(); } @@ -586,7 +586,7 @@ hello world! ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); if (ImGui.CollapsingHeader("Textures") && material.ImGuiTextures(icons, model)) { - _openTextureViewer = true; + _ti_open = true; } ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); @@ -618,14 +618,14 @@ hello world! } } - private void DrawTextureViewer(Snooper s) + private void DrawTextureInspector(Snooper s) { - if (ImGui.Begin("Texture Viewer", ref _openTextureViewer, ImGuiWindowFlags.NoScrollbar) && + if (ImGui.Begin("Texture Inspector", ref _ti_open, ImGuiWindowFlags.NoScrollbar) && s.Renderer.Options.TryGetModel(out var model) && s.Renderer.Options.TryGetSection(model, out var section)) { - var vectors = model.Materials[section.MaterialIndex].ImGuiTextureViewer(s.Renderer.Options.Icons, model); - if (_overlayUvOverTexture) + var vectors = model.Materials[section.MaterialIndex].ImGuiTextureInspector(s.Renderer.Options.Icons["noimage"]); + if (_ti_overlayUv) { var size = vectors[0]; var drawList = ImGui.GetWindowDrawList(); @@ -637,8 +637,8 @@ hello world! } Popup(() => { - if (ImGui.MenuItem("Overlay UVs", null, _overlayUvOverTexture)) - _overlayUvOverTexture = !_overlayUvOverTexture; + if (ImGui.MenuItem("Overlay UVs", null, _ti_overlayUv)) + _ti_overlayUv = !_ti_overlayUv; }); } ImGui.End(); // if window is collapsed