diff --git a/FModel/Framework/ImGuiController.cs b/FModel/Framework/ImGuiController.cs index 5237b1f1..d3a6a186 100644 --- a/FModel/Framework/ImGuiController.cs +++ b/FModel/Framework/ImGuiController.cs @@ -33,6 +33,7 @@ public class ImGuiController : IDisposable private int _windowHeight; private ImFontPtr _normal; + private ImFontPtr _bold; private ImFontPtr _semiBold; private readonly System.Numerics.Vector2 _scaleFactor = System.Numerics.Vector2.One; @@ -53,6 +54,7 @@ public class ImGuiController : IDisposable ImGui.SetCurrentContext(context); var io = ImGui.GetIO(); _normal = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeui.ttf", 16); + _bold = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeuib.ttf", 16); _semiBold = io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\seguisb.ttf", 16); io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset; @@ -69,9 +71,14 @@ public class ImGuiController : IDisposable _frameBegun = true; } + public void Bold() => PushFont(_bold); public void SemiBold() => PushFont(_semiBold); - public void Normal() => PushFont(_normal); - public void PopFont() => ImGui.PopFont(); + + public void PopFont() + { + ImGui.PopFont(); + PushFont(_normal); + } private void PushFont(ImFontPtr ptr) => ImGui.PushFont(ptr); diff --git a/FModel/Resources/default.frag b/FModel/Resources/default.frag index e5a91916..2a392bb5 100644 --- a/FModel/Resources/default.frag +++ b/FModel/Resources/default.frag @@ -50,11 +50,7 @@ uniform Parameters uParameters; uniform int uNumTexCoords; uniform vec3 uViewPos; uniform vec3 uViewDir; -uniform bool bDiffuseOnly; -uniform bool bVertexColors; -uniform bool bVertexNormals; -uniform bool bVertexTangent; -uniform bool bVertexTexCoords; +uniform bool bVertexColors[6]; out vec4 FragColor; @@ -121,7 +117,7 @@ vec3 CalcPBRLight(int layer, vec3 normals) vec3 kS = f; vec3 kD = 1.0 - kS; - kD *= 1.0 - max(0.0f, dot(v, reflect(-v, normals)) * specular_masks.g); + kD *= max(0.0f, dot(v, reflect(-v, normals)) * specular_masks.g); vec3 specBrdfNom = ggxDistribution(roughness, nDotH) * f * geomSmith(roughness, nDotL) * geomSmith(roughness, nDotV); float specBrdfDenom = 4.0f * nDotV * nDotL + 0.0001f; @@ -135,19 +131,19 @@ vec3 CalcPBRLight(int layer, vec3 normals) void main() { - if (bVertexColors) + if (bVertexColors[2]) { FragColor = fColor; } - else if (bVertexNormals) + else if (bVertexColors[3]) { FragColor = vec4(fNormal, 1); } - else if (bVertexTangent) + else if (bVertexColors[4]) { FragColor = vec4(fTangent, 1); } - else if (bVertexTexCoords) + else if (bVertexColors[5]) { FragColor = vec4(fTexCoords, 0, 1); } @@ -176,7 +172,7 @@ void main() vec4 emissive = SamplerToVector(uParameters.Emissive[layer].Sampler); result += uParameters.Emissive[layer].Color.rgb * emissive.rgb * uParameters.EmissiveMult; - if (!bDiffuseOnly) + if (!bVertexColors[1]) { result += CalcPBRLight(layer, normals); } diff --git a/FModel/Settings/UserSettings.cs b/FModel/Settings/UserSettings.cs index bd06bc0d..d7eb2fba 100644 --- a/FModel/Settings/UserSettings.cs +++ b/FModel/Settings/UserSettings.cs @@ -621,6 +621,20 @@ namespace FModel.Settings set => SetProperty(ref _lodExportFormat, value); } + private bool _showSkybox = true; + public bool ShowSkybox + { + get => _showSkybox; + set => SetProperty(ref _showSkybox, value); + } + + private bool _showGrid = true; + public bool ShowGrid + { + get => _showGrid; + set => SetProperty(ref _showGrid, value); + } + private bool _previewStaticMeshes = true; public bool PreviewStaticMeshes { diff --git a/FModel/Views/Snooper/Cache.cs b/FModel/Views/Snooper/Cache.cs index efdf4a18..a85f0603 100644 --- a/FModel/Views/Snooper/Cache.cs +++ b/FModel/Views/Snooper/Cache.cs @@ -27,6 +27,7 @@ public class Cache : IDisposable _game = Services.ApplicationService.ApplicationView.CUE4Parse.Game; Icons["material"] = new Texture("materialicon"); + Icons["noimage"] = new Texture("T_Placeholder_Item_Image"); } public bool TryGetCachedModel(UStaticMesh o, out Model model) diff --git a/FModel/Views/Snooper/Camera.cs b/FModel/Views/Snooper/Camera.cs index aacb5a1a..a6ec5016 100644 --- a/FModel/Views/Snooper/Camera.cs +++ b/FModel/Views/Snooper/Camera.cs @@ -1,4 +1,5 @@ using System; +using ImGuiNET; using OpenTK.Mathematics; namespace FModel.Views.Snooper; @@ -103,4 +104,25 @@ public class Camera return result; } + + private const float _step = 0.01f; + private const float _zero = 0.000001f; // doesn't actually work if _infinite is used as max value /shrug + private const float _infinite = 0.0f; + private const ImGuiSliderFlags _clamp = ImGuiSliderFlags.AlwaysClamp; + public void ImGuiCamera() + { + ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new System.Numerics.Vector2(8, 3)); + ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new System.Numerics.Vector2(0, 1)); + if (ImGui.BeginTable("camera_editor", 2)) + { + SnimGui.Layout("Speed");ImGui.PushID(1); + ImGui.DragFloat("", ref Speed, _step, _zero, _infinite, "%.2f s/m", _clamp); + ImGui.PopID();SnimGui.Layout("Far Plane");ImGui.PushID(2); + ImGui.DragFloat("", ref Far, 0.1f, 0.1f, Far * 2f, "%.2f m", _clamp); + ImGui.PopID(); + + ImGui.EndTable(); + } + ImGui.PopStyleVar(2); + } } diff --git a/FModel/Views/Snooper/Grid.cs b/FModel/Views/Snooper/Grid.cs index 0e985146..e839a239 100644 --- a/FModel/Views/Snooper/Grid.cs +++ b/FModel/Views/Snooper/Grid.cs @@ -1,5 +1,6 @@ using System; using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; namespace FModel.Views.Snooper; @@ -38,17 +39,17 @@ public class Grid : IDisposable _vao.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0); // position } - public void Render(Camera camera) + public void Render(Matrix4 viewMatrix, Matrix4 projMatrix, float near, float far) { GL.Disable(EnableCap.DepthTest); _vao.Bind(); _shader.Use(); - _shader.SetUniform("view", camera.GetViewMatrix()); - _shader.SetUniform("proj", camera.GetProjectionMatrix()); - _shader.SetUniform("uNear", camera.Near); - _shader.SetUniform("uFar", camera.Far); + _shader.SetUniform("view", viewMatrix); + _shader.SetUniform("proj", projMatrix); + _shader.SetUniform("uNear", near); + _shader.SetUniform("uFar", far); GL.DrawArrays(PrimitiveType.Triangles, 0, Indices.Length); GL.Enable(EnableCap.DepthTest); diff --git a/FModel/Views/Snooper/Material.cs b/FModel/Views/Snooper/Material.cs index fcabe597..c7650b6d 100644 --- a/FModel/Views/Snooper/Material.cs +++ b/FModel/Views/Snooper/Material.cs @@ -17,6 +17,7 @@ public class Material : IDisposable public readonly CMaterialParams2 Parameters; public string Name; public int SelectedChannel; + public int SelectedTexture; public bool IsUsed; public Texture[] Diffuse; @@ -213,21 +214,21 @@ public class Material : IDisposable ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(0, 1)); if (ImGui.BeginTable("parameters", 2)) { - Layout("Emissive Multiplier");ImGui.PushID(1); + SnimGui.Layout("Emissive Multiplier");ImGui.PushID(1); ImGui.DragFloat("", ref EmissiveMult, _step, _zero, _infinite, _mult, _clamp); - ImGui.PopID();Layout("UV Scale");ImGui.PushID(2); + ImGui.PopID();SnimGui.Layout("UV Scale");ImGui.PushID(2); ImGui.DragFloat("", ref UVScale, _step, _zero, _infinite, _mult, _clamp); ImGui.PopID(); if (HasM) { - Layout("Ambient Occlusion");ImGui.PushID(3); + SnimGui.Layout("Ambient Occlusion");ImGui.PushID(3); ImGui.DragFloat("", ref M.AmbientOcclusion, _step, _zero, 1.0f, _mult, _clamp); - ImGui.PopID();Layout("Cavity");ImGui.PushID(4); + ImGui.PopID();SnimGui.Layout("Cavity");ImGui.PushID(4); ImGui.DragFloat("", ref M.Cavity, _step, _zero, 1.0f, _mult, _clamp); - ImGui.PopID();Layout("Skin Boost Exponent");ImGui.PushID(5); + ImGui.PopID();SnimGui.Layout("Skin Boost Exponent");ImGui.PushID(5); ImGui.DragFloat("", ref M.SkinBoost.Exponent, _step, _zero, _infinite, _mult, _clamp); - ImGui.PopID();Layout("Skin Boost Color");ImGui.PushID(6); + ImGui.PopID();SnimGui.Layout("Skin Boost Color");ImGui.PushID(6); ImGui.ColorEdit3("", ref M.SkinBoost.Color); ImGui.PopID(); } @@ -242,35 +243,27 @@ public class Material : IDisposable { foreach ((string key, T value) in dictionary.Reverse()) { - Layout(key, true); + SnimGui.Layout(key, true); var text = $"{value:N}"; if (center) ImGui.SetCursorPosX(ImGui.GetCursorPosX() + (ImGui.GetColumnWidth() - ImGui.CalcTextSize(text).X) / 2); if (wrap) ImGui.TextWrapped(text); else ImGui.Text(text); - TooltipCopy(text); + SnimGui.TooltipCopy(text); } ImGui.EndTable(); } } - private void Layout(string name, bool tooltip = false) + public IntPtr? GetSelectedTexture() { - ImGui.TableNextRow(); - ImGui.TableSetColumnIndex(0); - ImGui.Spacing();ImGui.SameLine();ImGui.Text(name); - if (tooltip) TooltipCopy(name); - ImGui.TableSetColumnIndex(1); - ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X); - } - - private void TooltipCopy(string name) - { - if (ImGui.IsItemHovered()) + return SelectedTexture switch { - ImGui.BeginTooltip(); - ImGui.Text(name); - ImGui.EndTooltip(); - } - if (ImGui.IsItemClicked()) ImGui.SetClipboardText(name); + 0 => Diffuse[SelectedChannel]?.GetPointer(), + 1 => Normals[SelectedChannel]?.GetPointer(), + 2 => SpecularMasks[SelectedChannel]?.GetPointer(), + 3 => M.Texture?.GetPointer(), + 4 => Emissive[SelectedChannel]?.GetPointer(), + _ => null + }; } public void Dispose() diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs index 2c0063f4..5e3b0ef0 100644 --- a/FModel/Views/Snooper/Model.cs +++ b/FModel/Views/Snooper/Model.cs @@ -47,10 +47,6 @@ public class Model : IDisposable public bool Wireframe; public bool IsSetup; public bool IsSelected; - public bool bVertexColors; - public bool bVertexNormals; - public bool bVertexTangent; - public bool bVertexTexCoords; public int SelectedInstance; public float MorphTime; @@ -256,10 +252,6 @@ public class Model : IDisposable _vao.Bind(); shader.SetUniform("uMorphTime", MorphTime); shader.SetUniform("uNumTexCoords", NumTexCoords); - shader.SetUniform("bVertexColors", bVertexColors); - shader.SetUniform("bVertexNormals", bVertexNormals); - shader.SetUniform("bVertexTangent", bVertexTangent); - shader.SetUniform("bVertexTexCoords", bVertexTexCoords); GL.PolygonMode(MaterialFace.FrontAndBack, Wireframe ? PolygonMode.Line : PolygonMode.Fill); for (int section = 0; section < Sections.Length; section++) diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index 78169992..c69949c7 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -13,16 +13,21 @@ using CUE4Parse.UE4.Assets.Exports.Texture; using CUE4Parse.UE4.Objects.Core.Math; using CUE4Parse.UE4.Objects.Engine; using CUE4Parse.UE4.Objects.UObject; +using FModel.Settings; using Vector3 = OpenTK.Mathematics.Vector3; namespace FModel.Views.Snooper; public class Renderer : IDisposable { + private readonly Skybox _skybox; + private readonly Grid _grid; private Shader _shader; private Shader _outline; - public bool bDiffuseOnly; + public bool ShowSkybox; + public bool ShowGrid; + public int VertexColor; public PickingTexture Picking { get; } public Cache Cache { get; } @@ -30,9 +35,16 @@ public class Renderer : IDisposable public Renderer(int width, int height) { + _skybox = new Skybox(); + _grid = new Grid(); + Picking = new PickingTexture(width, height); Cache = new Cache(); Settings = new Options(); + + ShowSkybox = UserSettings.Default.ShowSkybox; + ShowGrid = UserSettings.Default.ShowGrid; + VertexColor = 0; // default } public Camera Load(CancellationToken cancellationToken, UObject export) @@ -69,6 +81,9 @@ public class Renderer : IDisposable public void Setup() { + _skybox.Setup(); + _grid.Setup(); + _shader = new Shader(); _outline = new Shader("outline"); @@ -81,9 +96,16 @@ public class Renderer : IDisposable var viewMatrix = cam.GetViewMatrix(); var projMatrix = cam.GetProjectionMatrix(); - // render pass + if (ShowSkybox) _skybox.Render(viewMatrix, projMatrix); + if (ShowGrid) _grid.Render(viewMatrix, projMatrix, cam.Near, cam.Far); + _shader.Render(viewMatrix, cam.Position, cam.Direction, projMatrix); - _shader.SetUniform("bDiffuseOnly", bDiffuseOnly); + for (int i = 0; i < 6; i++) + { + _shader.SetUniform($"bVertexColors[{i}]", i == VertexColor); + } + + // render pass foreach (var model in Cache.Models.Values) { if (!model.Show) continue; @@ -276,6 +298,11 @@ public class Renderer : IDisposable public void Dispose() { + UserSettings.Default.ShowSkybox = ShowSkybox; + UserSettings.Default.ShowGrid = ShowGrid; + + _skybox?.Dispose(); + _grid?.Dispose(); _shader.Dispose(); _outline.Dispose(); Picking.Dispose(); diff --git a/FModel/Views/Snooper/Skybox.cs b/FModel/Views/Snooper/Skybox.cs index f04316f8..89529921 100644 --- a/FModel/Views/Snooper/Skybox.cs +++ b/FModel/Views/Snooper/Skybox.cs @@ -1,5 +1,6 @@ using System; using OpenTK.Graphics.OpenGL4; +using OpenTK.Mathematics; namespace FModel.Views.Snooper; @@ -78,7 +79,7 @@ public class Skybox : IDisposable _vao.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0); // position } - public void Render(Camera camera) + public void Render(Matrix4 viewMatrix, Matrix4 projMatrix) { GL.DepthFunc(DepthFunction.Lequal); @@ -87,12 +88,11 @@ public class Skybox : IDisposable _cubeMap.Bind(TextureUnit.Texture0); _shader.Use(); - var view = camera.GetViewMatrix(); - view.M41 = 0; - view.M42 = 0; - view.M43 = 0; - _shader.SetUniform("uView", view); - _shader.SetUniform("uProjection", camera.GetProjectionMatrix()); + viewMatrix.M41 = 0; + viewMatrix.M42 = 0; + viewMatrix.M43 = 0; + _shader.SetUniform("uView", viewMatrix); + _shader.SetUniform("uProjection", projMatrix); _shader.SetUniform("cubemap", 0); diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs index b72e366c..77dcbf88 100644 --- a/FModel/Views/Snooper/SnimGui.cs +++ b/FModel/Views/Snooper/SnimGui.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Generic; -using CUE4Parse.UE4.Assets.Exports.Material; -using CUE4Parse.UE4.Objects.Core.Math; using CUE4Parse.UE4.Objects.Core.Misc; using FModel.Framework; using ImGuiNET; @@ -18,9 +16,9 @@ public class SnimGui private bool _viewportFocus; private bool _swapAwareness; - private readonly Vector4 _accentColor = new (32, 107, 212, 1f); - private readonly Vector4 _alertColor = new (212, 146, 32, 1f); - private readonly Vector4 _errorColor = new (194, 43, 43, 1f); + private readonly Vector4 _accentColor = new (0.125f, 0.42f, 0.831f, 1.0f); + private readonly Vector4 _alertColor = new (0.831f, 0.573f, 0.125f, 1.0f); + private readonly Vector4 _errorColor = new (0.761f, 0.169f, 0.169f, 1.0f); private const ImGuiCond _firstUse = ImGuiCond.FirstUseEver; // switch to FirstUseEver once the docking branch will not be useful anymore... private const uint _dockspaceId = 1337; @@ -38,15 +36,9 @@ public class SnimGui DrawNavbar(); SectionWindow("Material Inspector", s.Renderer, DrawMaterialInspector, false); - SectionWindow("UV Channels", s.Renderer, DrawUvChannels); Window("Timeline", () => {}); - Window("Camera", () => - { - ImGui.DragFloat("Speed", ref s.Camera.Speed, 0.01f, 0.05f); - ImGui.DragFloat("Far Plane", ref s.Camera.Far, 0.1f, 5f, s.Camera.Far * 2f, "%.2f m", ImGuiSliderFlags.AlwaysClamp); - }); - Window("World", () => ImGui.Checkbox("Diffuse Only", ref s.Renderer.bDiffuseOnly)); + Window("World", () => DrawWorld(s), false); Window("Sockets", () => DrawSockets(s)); DrawOuliner(s); @@ -58,6 +50,42 @@ public class SnimGui Controller.Render(); } + private void DrawWorld(Snooper s) + { + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); + if (ImGui.CollapsingHeader("Editor")) + { + ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(8, 3)); + ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(0, 1)); + if (ImGui.BeginTable("world_editor", 2)) + { + Layout("Skybox");ImGui.PushID(1); + ImGui.Checkbox("", ref s.Renderer.ShowSkybox); + ImGui.PopID();Layout("Grid");ImGui.PushID(2); + ImGui.Checkbox("", ref s.Renderer.ShowGrid); + ImGui.PopID();Layout("Vertex Colors");ImGui.PushID(3); + ImGui.Combo("vertex_colors", ref s.Renderer.VertexColor, + "Default\0Diffuse Only\0Colors\0Normals\0Tangent\0Texture Coordinates\0"); + ImGui.PopID(); + + ImGui.EndTable(); + } + ImGui.PopStyleVar(2); + } + + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); + if (ImGui.CollapsingHeader("Camera")) + { + s.Camera.ImGuiCamera(); + } + + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); + if (ImGui.CollapsingHeader("Lights")) + { + + } + } + private void DrawDockSpace(Vector2i size) { const ImGuiWindowFlags flags = @@ -137,6 +165,9 @@ public class SnimGui if (ImGui.BeginPopupContextItem()) { s.Renderer.Settings.SelectModel(guid); + if (ImGui.MenuItem("Show", null, model.Show)) model.Show = !model.Show; + if (ImGui.MenuItem("Wireframe", null, model.Wireframe)) model.Wireframe = !model.Wireframe; + ImGui.Separator(); if (ImGui.Selectable("Save")) { @@ -148,7 +179,6 @@ public class SnimGui s.WindowShouldClose(true, false); } ImGui.EndDisabled(); - ImGui.Separator(); if (ImGui.Selectable("Delete")) s.Renderer.Cache.Models.Remove(guid); if (ImGui.Selectable("Deselect")) s.Renderer.Settings.SelectModel(Guid.Empty); ImGui.Separator(); @@ -205,20 +235,11 @@ public class SnimGui ImGui.Text($"Entity: ({model.Type}) {model.Name}"); ImGui.Text($"Guid: {s.Renderer.Settings.SelectedModel.ToString(EGuidFormats.UniqueObjectGuid)}"); ImGui.Spacing(); - ImGui.Columns(3, "Actions", false); if (ImGui.Button("Go To")) { var instancePos = model.Transforms[model.SelectedInstance].Position; s.Camera.Position = new Vector3(instancePos.X, instancePos.Y, instancePos.Z); } - ImGui.NextColumn(); ImGui.Checkbox("Show", ref model.Show); - ImGui.NextColumn(); ImGui.BeginDisabled(!model.Show); ImGui.Checkbox("Wire", ref model.Wireframe); ImGui.EndDisabled(); - ImGui.Columns(4); - ImGui.NextColumn(); ImGui.BeginDisabled(!model.HasVertexColors); ImGui.Checkbox("Colors", ref model.bVertexColors); ImGui.EndDisabled(); - ImGui.NextColumn(); ImGui.Checkbox("Normals", ref model.bVertexNormals); - ImGui.NextColumn(); ImGui.Checkbox("Tangent", ref model.bVertexTangent); - ImGui.NextColumn(); ImGui.Checkbox("Coords", ref model.bVertexTexCoords); - ImGui.Columns(1); ImGui.Spacing(); if (ImGui.BeginTabBar("tabbar_details", ImGuiTabBarFlags.None)) { @@ -402,32 +423,6 @@ public class SnimGui ImGui.PopStyleVar(); } - private void DrawUvChannels(Dictionary icons, Model model, Section section) - { - var width = ImGui.GetContentRegionAvail().X; - var material = model.Materials[section.MaterialIndex]; - - ImGui.PushID(0); ImGui.BeginDisabled(model.NumTexCoords < 2); - ImGui.SetNextItemWidth(width); - ImGui.SliderInt("", ref material.SelectedChannel, 0, model.NumTexCoords - 1, "Channel %i", ImGuiSliderFlags.AlwaysClamp); - ImGui.EndDisabled(); ImGui.PopID(); - - ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); - if (ImGui.TreeNode("Textures")) - { - if (material.Diffuse.Length > 0) - { - var size = new Vector2(ImGui.GetContentRegionAvail().X / 5.75f); - DrawSquareTexture(material.Diffuse[material.SelectedChannel], size); ImGui.SameLine(); - DrawSquareTexture(material.Normals[material.SelectedChannel], size); ImGui.SameLine(); - DrawSquareTexture(material.SpecularMasks[material.SelectedChannel], size); ImGui.SameLine(); - DrawSquareTexture(material.M.Texture, size); ImGui.SameLine(); - DrawSquareTexture(material.Emissive[material.SelectedChannel], size); ImGui.SameLine(); - } - else CenteredTextColored(_errorColor, "no texture in material section"); - } - } - private void DrawMaterialInspector(Dictionary icons, Model model, Section section) { var material = model.Materials[section.MaterialIndex]; @@ -443,6 +438,27 @@ public class SnimGui material.ImGuiParameters(); } + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); + if (ImGui.CollapsingHeader("Textures")) + { + ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, new Vector2(8, 3)); + ImGui.PushStyleVar(ImGuiStyleVar.CellPadding, new Vector2(0, 1)); + if (ImGui.BeginTable("material_textures", 2)) + { + Layout("Channel");ImGui.PushID(1); ImGui.BeginDisabled(model.NumTexCoords < 2); + ImGui.DragInt("", ref material.SelectedChannel, 1, 0, model.NumTexCoords - 1, "UV %i", ImGuiSliderFlags.AlwaysClamp); + ImGui.EndDisabled();ImGui.PopID();Layout("Type");ImGui.PushID(2); + ImGui.Combo("texture_type", ref material.SelectedTexture, + "Diffuse\0Normals\0Specular\0Mask\0Emissive\0"); + ImGui.PopID(); + ImGui.EndTable(); + } + ImGui.PopStyleVar(2); + + ImGui.Image(material.GetSelectedTexture() ?? icons["noimage"].GetPointer(), new Vector2(ImGui.GetContentRegionAvail().X), Vector2.Zero, Vector2.One, Vector4.One, new Vector4(1.0f, 1.0f, 1.0f, 0.25f)); + ImGui.Spacing(); + } + ImGui.SetNextItemOpen(true, ImGuiCond.Appearing); if (ImGui.CollapsingHeader("Properties")) { @@ -458,7 +474,7 @@ public class SnimGui material.ImGuiDictionaries("colors", material.Parameters.Colors, true); ImGui.TreePop(); } - if (ImGui.TreeNode("Textures")) + if (ImGui.TreeNode("Referenced Textures")) { material.ImGuiDictionaries("textures", material.Parameters.Textures); ImGui.TreePop(); @@ -521,7 +537,7 @@ public class SnimGui { if (ImGui.Begin(name)) { - Controller.Normal(); + Controller.PopFont(); if (styled) PushStyleCompact(); content(); if (styled) PopStyleCompact(); @@ -555,8 +571,8 @@ public class SnimGui ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, style.ItemSpacing with { Y = style.ItemSpacing.Y * 0.6f }); } - private void NoMeshSelected() => CenteredTextColored(_errorColor, "no mesh selected"); - private void NoSectionSelected() => CenteredTextColored(_errorColor, "no section selected"); + private void NoMeshSelected() => CenteredTextColored(_errorColor, "No Mesh Selected"); + private void NoSectionSelected() => CenteredTextColored(_errorColor, "No Section Selected"); private void CenteredTextColored(Vector4 color, string text) { var region = ImGui.GetContentRegionAvail(); @@ -564,7 +580,30 @@ public class SnimGui ImGui.SetCursorPos(new Vector2( ImGui.GetCursorPosX() + (region.X - size.X) / 2, ImGui.GetCursorPosY() + (region.Y - size.Y) / 2)); + Controller.Bold(); ImGui.TextColored(color, text); + Controller.PopFont(); + } + + public static void Layout(string name, bool tooltip = false) + { + ImGui.TableNextRow(); + ImGui.TableSetColumnIndex(0); + ImGui.Spacing();ImGui.SameLine();ImGui.Text(name); + if (tooltip) TooltipCopy(name); + ImGui.TableSetColumnIndex(1); + ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X); + } + + public static void TooltipCopy(string name) + { + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text(name); + ImGui.EndTooltip(); + } + if (ImGui.IsItemClicked()) ImGui.SetClipboardText(name); } private void DrawSquareTexture(Texture texture, Vector2 size) diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index 2f9692da..423a27d7 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -16,8 +16,6 @@ public class Snooper : GameWindow public readonly FramebufferObject Framebuffer; public readonly Renderer Renderer; - private readonly Skybox _skybox; - private readonly Grid _grid; private readonly SnimGui _gui; private float _previousSpeed; @@ -29,10 +27,7 @@ public class Snooper : GameWindow Framebuffer = new FramebufferObject(ClientSize); Renderer = new Renderer(ClientSize.X, ClientSize.Y); - _skybox = new Skybox(); - _grid = new Grid(); _gui = new SnimGui(ClientSize.X, ClientSize.Y); - _init = false; } @@ -79,7 +74,7 @@ public class Snooper : GameWindow base.OnLoad(); CenterWindow(); - GL.ClearColor(Color4.Red); + GL.ClearColor(Color4.Black); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Multisample); @@ -88,9 +83,6 @@ public class Snooper : GameWindow Framebuffer.Setup(); Renderer.Setup(); - - _skybox.Setup(); - _grid.Setup(); _init = true; } @@ -107,8 +99,6 @@ public class Snooper : GameWindow Framebuffer.Bind(); // switch to viewport background ClearWhatHasBeenDrawn(); // clear viewport background - _skybox.Render(Camera); - _grid.Render(Camera); Renderer.Render(Camera); Framebuffer.BindMsaa(); @@ -183,8 +173,6 @@ public class Snooper : GameWindow Framebuffer?.Dispose(); Renderer?.Dispose(); - _skybox?.Dispose(); - _grid?.Dispose(); _gui?.Controller.Dispose(); } }