diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs index f123c33e..f5795953 100644 --- a/FModel/Views/Snooper/Model.cs +++ b/FModel/Views/Snooper/Model.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Numerics; using CUE4Parse_Conversion.Meshes.PSK; +using ImGuiNET; using Silk.NET.OpenGL; namespace FModel.Views.Snooper; @@ -21,12 +22,15 @@ public class Model : IDisposable private Shader _shader; + public string Name; public uint[] Indices; public float[] Vertices; public Section[] Sections; - public Model(CBaseMeshLod lod, CMeshVertex[] vertices) + public Model(string name, CBaseMeshLod lod, CMeshVertex[] vertices) { + Name = name; + var sections = lod.Sections.Value; Sections = new Section[sections.Length]; Indices = new uint[sections.Sum(section => section.NumFaces * _faceSize)]; @@ -35,7 +39,7 @@ public Model(CBaseMeshLod lod, CMeshVertex[] vertices) for (var s = 0; s < sections.Length; s++) { var section = sections[s]; - Sections[s] = new Section((uint) section.NumFaces * _faceSize, section.FirstIndex, section); + Sections[s] = new Section(section.MaterialName, (uint) section.NumFaces * _faceSize, section.FirstIndex, section); for (uint face = 0; face < section.NumFaces; face++) { foreach (var f in _facesIndex) @@ -109,12 +113,15 @@ public void Bind(Camera camera) _shader.SetUniform("light.specular", Vector3.One); _shader.SetUniform("light.position", camera.Position); + ImGui.BeginTable("Sections", 2, ImGuiTableFlags.RowBg); + ImGui.TableSetupColumn("Index", ImGuiTableColumnFlags.WidthFixed); + ImGui.TableSetupColumn("Material"); + ImGui.TableHeadersRow(); for (int section = 0; section < Sections.Length; section++) { - Sections[section].Bind(); - - _gl.DrawArrays(PrimitiveType.Triangles, Sections[section].FirstFaceIndex, Sections[section].FacesCount); + Sections[section].Bind(section); } + ImGui.EndTable(); } public void Dispose() diff --git a/FModel/Views/Snooper/Section.cs b/FModel/Views/Snooper/Section.cs index f85dbcfb..584d21d7 100644 --- a/FModel/Views/Snooper/Section.cs +++ b/FModel/Views/Snooper/Section.cs @@ -4,6 +4,7 @@ using CUE4Parse_Conversion.Meshes.PSK; using CUE4Parse_Conversion.Textures; using FModel.Settings; +using ImGuiNET; using Silk.NET.OpenGL; namespace FModel.Views.Snooper; @@ -19,12 +20,14 @@ public class Section : IDisposable // private Texture _metallicMap; private Texture _emissionMap; + public string Name; public uint FacesCount; public int FirstFaceIndex; public CMaterialParams Parameters; - public Section(uint facesCount, int firstFaceIndex, CMeshSection section) + public Section(string name, uint facesCount, int firstFaceIndex, CMeshSection section) { + Name = name; FacesCount = facesCount; FirstFaceIndex = firstFaceIndex; Parameters = new CMaterialParams(); @@ -72,11 +75,27 @@ public void Setup(GL gl) } } - public void Bind() + public void Bind(int index) { - if (Parameters.IsNull) - return; + ImGui.TableNextRow(); + ImGui.TableSetColumnIndex(0); + ImGui.Text(index.ToString()); + ImGui.TableSetColumnIndex(1); + ImGui.Text(Name); + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text($"Faces: {FacesCount}"); + ImGui.Text($"Face First Index: {FirstFaceIndex}"); + ImGui.Separator(); + ImGui.Text($"Diffuse: ({Parameters.Diffuse?.ExportType}) {Parameters.Diffuse?.Name}"); + ImGui.EndTooltip(); + } + + _gl.DrawArrays(PrimitiveType.Triangles, FirstFaceIndex, FacesCount); + + if (Parameters.IsNull) return; _diffuseMap?.Bind(TextureUnit.Texture0); _normalMap?.Bind(TextureUnit.Texture1); _specularMap?.Bind(TextureUnit.Texture2); diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index 6a932aac..6e08f056 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -5,6 +5,7 @@ using CUE4Parse.UE4.Assets.Exports.StaticMesh; using CUE4Parse.UE4.Objects.Core.Math; using CUE4Parse_Conversion.Meshes; +using ImGuiNET; using Silk.NET.Input; using Silk.NET.Maths; using Silk.NET.OpenGL; @@ -31,7 +32,7 @@ public class Snooper public Snooper(UObject export) { - const double ratio = .6; + const double ratio = .7; var x = System.Windows.SystemParameters.MaximizedPrimaryScreenWidth; var y = System.Windows.SystemParameters.MaximizedPrimaryScreenHeight; Width = Convert.ToInt32(x * ratio); @@ -54,13 +55,13 @@ public Snooper(UObject export) { case UStaticMesh st when st.TryConvert(out var mesh): { - _models[0] = new Model(mesh.LODs[0], mesh.LODs[0].Verts); + _models[0] = new Model(st.Name, mesh.LODs[0], mesh.LODs[0].Verts); SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO); break; } case USkeletalMesh sk when sk.TryConvert(out var mesh): { - _models[0] = new Model(mesh.LODs[0], mesh.LODs[0].Verts); + _models[0] = new Model(sk.Name, mesh.LODs[0], mesh.LODs[0].Verts); SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO); break; } @@ -88,9 +89,9 @@ private void OnLoad() _keyboard.KeyDown += KeyDown; foreach (var mouse in _input.Mice) { - mouse.Cursor.CursorMode = CursorMode.Raw; - mouse.MouseMove += OnMouseMove; - mouse.Scroll += OnMouseWheel; + // mouse.Cursor.CursorMode = CursorMode.Raw; + // mouse.MouseMove += OnMouseMove; + // mouse.Scroll += OnMouseWheel; } _gl = GL.GetApi(_window); @@ -122,12 +123,23 @@ private void OnRender(double deltaTime) _grid.Bind(_camera); + var padding = Theme(); + ImGui.Begin("ImGui.NET", ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoBackground); + ImGui.SetWindowSize(new Vector2(Width / 4f, Height)); + ImGui.SetWindowPos(new Vector2(0)); + foreach (var model in _models) { + ImGui.Text($"Entity: {model.Name}"); model.Bind(_camera); + ImGui.Separator(); } - ImGuiNET.ImGui.ShowAboutWindow(); + float framerate = ImGui.GetIO().Framerate; + string f = $"FPS: {framerate:0.#} ({1000.0f / framerate:0.##} ms)"; + ImGui.SetCursorPosY(ImGui.GetWindowHeight() - padding.Y - ImGui.CalcTextSize(f).Y); + ImGui.Text(f); + ImGui.End(); _controller.Render(); } @@ -195,9 +207,69 @@ private void OnClose() private void KeyDown(IKeyboard keyboard, Key key, int arg3) { - if (key == Key.Escape) + switch (key) { - _window.Close(); + case Key.Escape: + _window.Close(); + break; } } + + private Vector2 Theme() + { + var style = ImGui.GetStyle(); + style.FrameRounding = 4.0f; + style.GrabRounding = 4.0f; + + style.Colors[(int) ImGuiCol.Text] = new Vector4(0.95f, 0.96f, 0.98f, 1.00f); + style.Colors[(int) ImGuiCol.TextDisabled] = new Vector4(0.36f, 0.42f, 0.47f, 1.00f); + style.Colors[(int) ImGuiCol.WindowBg] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); + style.Colors[(int) ImGuiCol.ChildBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f); + style.Colors[(int) ImGuiCol.PopupBg] = new Vector4(0.08f, 0.08f, 0.08f, 0.94f); + style.Colors[(int) ImGuiCol.Border] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f); + style.Colors[(int) ImGuiCol.BorderShadow] = new Vector4(0.00f, 0.00f, 0.00f, 0.00f); + style.Colors[(int) ImGuiCol.FrameBg] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + style.Colors[(int) ImGuiCol.FrameBgHovered] = new Vector4(0.12f, 0.20f, 0.28f, 1.00f); + style.Colors[(int) ImGuiCol.FrameBgActive] = new Vector4(0.09f, 0.12f, 0.14f, 1.00f); + style.Colors[(int) ImGuiCol.TitleBg] = new Vector4(0.09f, 0.12f, 0.14f, 0.65f); + style.Colors[(int) ImGuiCol.TitleBgActive] = new Vector4(0.08f, 0.10f, 0.12f, 1.00f); + style.Colors[(int) ImGuiCol.TitleBgCollapsed] = new Vector4(0.00f, 0.00f, 0.00f, 0.51f); + style.Colors[(int) ImGuiCol.MenuBarBg] = new Vector4(0.15f, 0.18f, 0.22f, 1.00f); + style.Colors[(int) ImGuiCol.ScrollbarBg] = new Vector4(0.02f, 0.02f, 0.02f, 0.39f); + style.Colors[(int) ImGuiCol.ScrollbarGrab] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + style.Colors[(int) ImGuiCol.ScrollbarGrabHovered] = new Vector4(0.18f, 0.22f, 0.25f, 1.00f); + style.Colors[(int) ImGuiCol.ScrollbarGrabActive] = new Vector4(0.09f, 0.21f, 0.31f, 1.00f); + style.Colors[(int) ImGuiCol.CheckMark] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); + style.Colors[(int) ImGuiCol.SliderGrab] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); + style.Colors[(int) ImGuiCol.SliderGrabActive] = new Vector4(0.37f, 0.61f, 1.00f, 1.00f); + style.Colors[(int) ImGuiCol.Button] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + style.Colors[(int) ImGuiCol.ButtonHovered] = new Vector4(0.28f, 0.56f, 1.00f, 1.00f); + style.Colors[(int) ImGuiCol.ButtonActive] = new Vector4(0.06f, 0.53f, 0.98f, 1.00f); + style.Colors[(int) ImGuiCol.Header] = new Vector4(0.20f, 0.25f, 0.29f, 0.55f); + style.Colors[(int) ImGuiCol.HeaderHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f); + style.Colors[(int) ImGuiCol.HeaderActive] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[(int) ImGuiCol.Separator] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + style.Colors[(int) ImGuiCol.SeparatorHovered] = new Vector4(0.10f, 0.40f, 0.75f, 0.78f); + style.Colors[(int) ImGuiCol.SeparatorActive] = new Vector4(0.10f, 0.40f, 0.75f, 1.00f); + style.Colors[(int) ImGuiCol.ResizeGrip] = new Vector4(0.26f, 0.59f, 0.98f, 0.25f); + style.Colors[(int) ImGuiCol.ResizeGripHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.67f); + style.Colors[(int) ImGuiCol.ResizeGripActive] = new Vector4(0.26f, 0.59f, 0.98f, 0.95f); + style.Colors[(int) ImGuiCol.Tab] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); + style.Colors[(int) ImGuiCol.TabHovered] = new Vector4(0.26f, 0.59f, 0.98f, 0.80f); + style.Colors[(int) ImGuiCol.TabActive] = new Vector4(0.20f, 0.25f, 0.29f, 1.00f); + style.Colors[(int) ImGuiCol.TabUnfocused] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); + style.Colors[(int) ImGuiCol.TabUnfocusedActive] = new Vector4(0.11f, 0.15f, 0.17f, 1.00f); + style.Colors[(int) ImGuiCol.PlotLines] = new Vector4(0.61f, 0.61f, 0.61f, 1.00f); + style.Colors[(int) ImGuiCol.PlotLinesHovered] = new Vector4(1.00f, 0.43f, 0.35f, 1.00f); + style.Colors[(int) ImGuiCol.PlotHistogram] = new Vector4(0.90f, 0.70f, 0.00f, 1.00f); + style.Colors[(int) ImGuiCol.PlotHistogramHovered] = new Vector4(1.00f, 0.60f, 0.00f, 1.00f); + style.Colors[(int) ImGuiCol.TextSelectedBg] = new Vector4(0.26f, 0.59f, 0.98f, 0.35f); + style.Colors[(int) ImGuiCol.DragDropTarget] = new Vector4(1.00f, 1.00f, 0.00f, 0.90f); + style.Colors[(int) ImGuiCol.NavHighlight] = new Vector4(0.26f, 0.59f, 0.98f, 1.00f); + style.Colors[(int) ImGuiCol.NavWindowingHighlight] = new Vector4(1.00f, 1.00f, 1.00f, 0.70f); + style.Colors[(int) ImGuiCol.NavWindowingDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.20f); + style.Colors[(int) ImGuiCol.ModalWindowDimBg] = new Vector4(0.80f, 0.80f, 0.80f, 0.35f); + + return style.WindowPadding; + } }