imgui stuff

This commit is contained in:
4sval 2022-09-03 23:50:02 +02:00
parent 97b03ed0c7
commit 872b01c7ef
4 changed files with 75 additions and 15 deletions

View File

@ -204,6 +204,9 @@ public static class Utils
return string.Empty;
}
public static string FixPath(string weirdPath) =>
_applicationView.CUE4Parse.Provider.FixPath(weirdPath, StringComparison.Ordinal);
public static void DrawCenteredMultilineText(SKCanvas c, string text, int maxCount, int size, int margin, SKTextAlign side, SKRect area, SKPaint paint)
{
var lineHeight = paint.TextSize * 1.2f;

View File

@ -79,21 +79,21 @@ public class Section : IDisposable
{
var mip = diffuse.GetFirstMip();
TextureDecoder.DecodeTexture(mip, diffuse.Format, diffuse.isNormalMap, platform, out var data, out _);
Textures[0] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
Textures[0] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, diffuse);
}
if (Parameters.Normal is UTexture2D { IsVirtual: false } normal)
{
var mip = normal.GetFirstMip();
TextureDecoder.DecodeTexture(mip, normal.Format, normal.isNormalMap, platform, out var data, out _);
Textures[1] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
Textures[1] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, normal);
}
if (Parameters.Specular is UTexture2D { IsVirtual: false } specular)
{
var mip = specular.GetFirstMip();
SwapSpecular(specular, mip, platform, out var data);
Textures[2] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
Textures[2] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, specular);
}
if (Parameters.HasTopEmissiveTexture &&
@ -102,7 +102,7 @@ public class Section : IDisposable
{
var mip = emissive.GetFirstMip();
TextureDecoder.DecodeTexture(mip, emissive.Format, emissive.isNormalMap, platform, out var data, out _);
Textures[3] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY);
Textures[3] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, emissive);
EmissionColor = new Vector4(emissiveColor.R, emissiveColor.G, emissiveColor.B, emissiveColor.A);
}
}
@ -240,7 +240,7 @@ public class Section : IDisposable
shader.SetUniform("light.diffuse", _diffuseLight);
shader.SetUniform("light.specular", _specularLight);
_gl.PolygonMode(MaterialFace.Front, Wireframe ? PolygonMode.Line : PolygonMode.Fill);
_gl.PolygonMode(MaterialFace.FrontAndBack, Wireframe ? PolygonMode.Line : PolygonMode.Fill);
if (Show) _gl.DrawArrays(PrimitiveType.Triangles, FirstFaceIndex, FacesCount);
}

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Windows;
using FModel.Creator;
using ImGuiNET;
using Silk.NET.Input;
using Silk.NET.Maths;
@ -255,13 +257,12 @@ public class SnimGui : IDisposable
ImGui.BeginGroup();
ImGui.Checkbox("Show", ref section.Show);
ImGui.Checkbox("Wireframe", ref section.Wireframe);
ImGui.Checkbox("3", ref section.Wireframe);
ImGui.Checkbox("4", ref section.Wireframe);
ImGui.EndGroup();
ImGui.SameLine();
ImGui.BeginGroup();
if (section.HasDiffuseColor)
{
ImGui.SetNextItemWidth(300);
ImGui.ColorEdit4(section.TexturesLabels[0], ref section.DiffuseColor, ImGuiColorEditFlags.AlphaPreview | ImGuiColorEditFlags.AlphaBar);
}
else
@ -274,6 +275,33 @@ public class SnimGui : IDisposable
ImGui.SameLine();
ImGui.BeginGroup();
ImGui.Image(texture.GetPointer(), new Vector2(88), Vector2.Zero, Vector2.One, Vector4.One, new Vector4(1, 1, 1, .5f));
if (ImGui.IsItemHovered())
{
ImGui.BeginTooltip();
ImGui.Text($"Type: ({texture.Format}) {texture.Type}");
ImGui.Text($"Texture: {texture.Path}.{texture.Name}");
ImGui.Text($"Imported: {texture.ImportedWidth}x{texture.ImportedHeight}");
ImGui.Text($"Mip Used: {texture.Width}x{texture.Height}");
ImGui.Spacing();
ImGui.TextDisabled(texture.Label);
ImGui.EndTooltip();
}
if (ImGui.IsItemClicked())
{
Application.Current.Dispatcher.Invoke(delegate
{
Clipboard.SetText(Utils.FixPath(texture.Path));
texture.Label = "(?) Copied to Clipboard";
});
}
if (i == 3) // emissive, show color
{
ImGui.SameLine();
ImGui.SetNextItemWidth(300);
ImGui.ColorEdit4($"{section.TexturesLabels[i]} Color", ref section.EmissionColor, ImGuiColorEditFlags.NoAlpha);
}
var text = section.TexturesLabels[i];
var width = ImGui.GetCursorPos().X;
ImGui.SetCursorPosX(width + ImGui.CalcTextSize(text).X * 0.5f);
@ -381,7 +409,7 @@ public class SnimGui : IDisposable
io.ConfigWindowsMoveFromTitleBarOnly = true;
io.ConfigDockingWithShift = true;
// style.WindowPadding = Vector2.Zero;
style.WindowMenuButtonPosition = ImGuiDir.Right;
// 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.149f, 0.149f, 0.188f, 0.35f);

View File

@ -1,6 +1,7 @@
using Silk.NET.OpenGL;
using System;
using System.Windows;
using CUE4Parse.UE4.Assets.Exports.Texture;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
@ -12,18 +13,32 @@ public class Texture : IDisposable
private readonly GL _gl;
private readonly TextureType _type;
public readonly string Type;
public readonly string Name;
public readonly string Path;
public readonly EPixelFormat Format;
public readonly uint ImportedWidth;
public readonly uint ImportedHeight;
public readonly uint Width;
public readonly uint Height;
public string Label;
public Texture(GL gl, TextureType type)
{
_gl = gl;
_handle = _gl.GenTexture();
_type = type;
Label = "(?) Click to Copy";
}
public Texture(GL gl, uint width, uint height) : this(gl, TextureType.MsaaFramebuffer)
{
Width = width;
Height = height;
Bind(TextureUnit.Texture0);
_gl.TexImage2DMultisample(TextureTarget.Texture2DMultisample, Constants.SAMPLES_COUNT, InternalFormat.Rgb, width, height, Silk.NET.OpenGL.Boolean.True);
_gl.TexImage2DMultisample(TextureTarget.Texture2DMultisample, Constants.SAMPLES_COUNT, InternalFormat.Rgb, Width, Height, Silk.NET.OpenGL.Boolean.True);
_gl.TexParameter(TextureTarget.Texture2DMultisample, TextureParameterName.TextureMinFilter, (int) GLEnum.Nearest);
_gl.TexParameter(TextureTarget.Texture2DMultisample, TextureParameterName.TextureMagFilter, (int) GLEnum.Nearest);
@ -35,9 +50,11 @@ public class Texture : IDisposable
public unsafe Texture(GL gl, int width, int height) : this(gl, TextureType.Framebuffer)
{
Width = (uint) width;
Height = (uint) height;
Bind(TextureUnit.Texture0);
_gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgb, (uint) width, (uint) height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, null);
_gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgb, Width, Height, 0, PixelFormat.Rgb, PixelType.UnsignedByte, null);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.Linear);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Linear);
@ -47,13 +64,21 @@ public class Texture : IDisposable
_gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, _handle, 0);
}
public unsafe Texture(GL gl, byte[] data, uint width, uint height) : this(gl, TextureType.Normal)
public unsafe Texture(GL gl, byte[] data, uint width, uint height, UTexture2D texture2D) : this(gl, TextureType.Normal)
{
Type = texture2D.ExportType;
Name = texture2D.Name;
Path = texture2D.Owner?.Name;
Format = texture2D.Format;
ImportedWidth = texture2D.ImportedSize.X;
ImportedHeight = texture2D.ImportedSize.Y;
Width = width;
Height = height;
Bind(TextureUnit.Texture0);
fixed (void* d = &data[0])
{
_gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, d);
_gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgba, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, d);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.LinearMipmapLinear);
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Linear);
@ -72,7 +97,9 @@ public class Texture : IDisposable
{
var info = Application.GetResourceStream(new Uri($"/FModel;component/Resources/{textures[t]}.png", UriKind.Relative));
using var img = Image.Load<Rgba32>(info.Stream);
_gl.TexImage2D(TextureTarget.TextureCubeMapPositiveX + t, 0, InternalFormat.Rgba8, (uint) img.Width, (uint) img.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, null);
Width = (uint) img.Width; // we don't care anyway
Height = (uint) img.Height; // we don't care anyway
_gl.TexImage2D(TextureTarget.TextureCubeMapPositiveX + t, 0, InternalFormat.Rgba8, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, null);
img.ProcessPixelRows(accessor =>
{
@ -95,10 +122,12 @@ public class Texture : IDisposable
public unsafe Texture(GL gl, uint width, uint height, IntPtr data) : this(gl, TextureType.Normal)
{
Width = width;
Height = height;
Bind(TextureTarget.Texture2D);
_gl.TexStorage2D(GLEnum.Texture2D, 1, SizedInternalFormat.Rgba8, width, height);
_gl.TexSubImage2D(GLEnum.Texture2D, 0, 0, 0, width, height, PixelFormat.Bgra, PixelType.UnsignedByte, (void*) data);
_gl.TexStorage2D(GLEnum.Texture2D, 1, SizedInternalFormat.Rgba8, Width, Height);
_gl.TexSubImage2D(GLEnum.Texture2D, 0, 0, 0, Width, Height, PixelFormat.Bgra, PixelType.UnsignedByte, (void*) data);
_gl.TexParameterI(GLEnum.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
_gl.TexParameterI(GLEnum.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);