From 4710d3afbccc7ee1f69f01aa293ef069a49f4af0 Mon Sep 17 00:00:00 2001 From: 4sval Date: Sun, 4 Sep 2022 10:18:15 +0200 Subject: [PATCH] append mode shortcut --- FModel/Views/Snooper/Section.cs | 21 ++++++----- FModel/Views/Snooper/SnimGui.cs | 6 +-- FModel/Views/Snooper/Snooper.cs | 66 ++++++++++++++++++++++++--------- FModel/Views/Snooper/Texture.cs | 4 +- 4 files changed, 64 insertions(+), 33 deletions(-) diff --git a/FModel/Views/Snooper/Section.cs b/FModel/Views/Snooper/Section.cs index c4b254bd..062c0195 100644 --- a/FModel/Views/Snooper/Section.cs +++ b/FModel/Views/Snooper/Section.cs @@ -7,6 +7,7 @@ using CUE4Parse_Conversion.Textures; using FModel.Services; using FModel.Settings; using Silk.NET.OpenGL; +using SkiaSharp; namespace FModel.Views.Snooper; @@ -78,22 +79,22 @@ public class Section : IDisposable else if (Parameters.Diffuse is UTexture2D { IsVirtual: false } diffuse) { 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, diffuse); + TextureDecoder.DecodeTexture(mip, diffuse.Format, diffuse.isNormalMap, platform, out var data, out var colorType); + Textures[0] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, 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, normal); + TextureDecoder.DecodeTexture(mip, normal.Format, normal.isNormalMap, platform, out var data, out var colorType); + Textures[1] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, 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, specular); + SwapSpecular(specular, mip, platform, out var data, out var colorType); + Textures[2] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, specular); } if (Parameters.HasTopEmissiveTexture && @@ -101,8 +102,8 @@ public class Section : IDisposable Parameters.Emissive is UTexture2D { IsVirtual: false } emissive) { 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, emissive); + TextureDecoder.DecodeTexture(mip, emissive.Format, emissive.isNormalMap, platform, out var data, out var colorType); + Textures[3] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, emissive); EmissionColor = new Vector4(emissiveColor.R, emissiveColor.G, emissiveColor.B, emissiveColor.A); } } @@ -122,9 +123,9 @@ public class Section : IDisposable /// Roughness on Green /// Ambient Occlusion on Red /// - private void SwapSpecular(UTexture2D specular, FTexture2DMipMap mip, ETexturePlatform platform, out byte[] data) + private void SwapSpecular(UTexture2D specular, FTexture2DMipMap mip, ETexturePlatform platform, out byte[] data, out SKColorType colorType) { - TextureDecoder.DecodeTexture(mip, specular.Format, specular.isNormalMap, platform, out data, out _); + TextureDecoder.DecodeTexture(mip, specular.Format, specular.isNormalMap, platform, out data, out colorType); switch (_game) { diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs index 8bf57a3d..2d3888d6 100644 --- a/FModel/Views/Snooper/SnimGui.cs +++ b/FModel/Views/Snooper/SnimGui.cs @@ -93,7 +93,7 @@ public class SnimGui : IDisposable if (ImGui.BeginMenu("Window")) { - ImGui.MenuItem("Append", "CTRL+A"); + ImGui.MenuItem("Append", "H"); ImGui.MenuItem("Close", "ESC"); ImGui.EndMenu(); } @@ -278,8 +278,8 @@ public class SnimGui : IDisposable if (ImGui.IsItemHovered()) { ImGui.BeginTooltip(); - ImGui.Text($"Type: ({texture.Format}) {texture.Type}"); - ImGui.Text($"Texture: {texture.Path}.{texture.Name}"); + ImGui.Text($"Type: ({texture.Format}) {texture.Type} \"{texture.Name}\""); + ImGui.Text($"Texture: {texture.Path}"); ImGui.Text($"Imported: {texture.ImportedWidth}x{texture.ImportedHeight}"); ImGui.Text($"Mip Used: {texture.Width}x{texture.Height}"); ImGui.Spacing(); diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index 8cf9b7ba..6359f668 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -36,6 +36,9 @@ public class Snooper private readonly List _models; private Vector2D _size; + private float _previousSpeed; + private bool _close; + private bool _append; public Snooper() { @@ -82,6 +85,8 @@ public class Snooper public void Run(UObject export) { + _close = false; + _append = false; switch (export) { case UStaticMesh st when st.TryConvert(out var mesh): @@ -100,7 +105,16 @@ public class Snooper throw new ArgumentOutOfRangeException(nameof(export)); } - _window.Run(); + _window.Initialize(); + while (!_close && !_append) + { + _window.DoEvents(); + _window.DoUpdate(); + _window.DoRender(); + } + _window.DoEvents(); + if (!_append) _window.Close(); // dispose + else _window.Reset(); } private void SetupCamera(FBox box) @@ -108,7 +122,12 @@ public class Snooper var far = box.Max.Max(); var center = box.GetCenter(); var position = new Vector3(0f, center.Z, box.Max.Y * 3); - _camera = new Camera(position, center, 0.01f, far * 50f, far / 2f); + var speed = far / 2f; + if (speed > _previousSpeed) + { + _camera = new Camera(position, center, 0.01f, far * 50f, speed); + _previousSpeed = _camera.Speed; + } } private void OnLoad() @@ -116,22 +135,29 @@ public class Snooper _window.SetWindowIcon(ref _icon); _window.Center(); - var input = _window.CreateInput(); - _keyboard = input.Keyboards[0]; - _mouse = input.Mice[0]; - - _gl = GL.GetApi(_window); - _gl.Enable(EnableCap.Multisample); - - _imGui = new SnimGui(_gl, _window, input); - - _framebuffer.Setup(_gl); - _skybox.Setup(_gl); - _grid.Setup(_gl); - - foreach (var model in _models) + if (_append) { - model.Setup(_gl); + _models[^1].Setup(_gl); + } + else + { + var input = _window.CreateInput(); + _keyboard = input.Keyboards[0]; + _mouse = input.Mice[0]; + + _gl = GL.GetApi(_window); + _gl.Enable(EnableCap.Multisample); + + _imGui = new SnimGui(_gl, _window, input); + + _framebuffer.Setup(_gl); + _skybox.Setup(_gl); + _grid.Setup(_gl); + + foreach (var model in _models) + { + model.Setup(_gl); + } } } @@ -192,8 +218,11 @@ public class Snooper _camera.Position += moveSpeed * _camera.Up; if (_keyboard.IsKeyPressed(Key.Q)) _camera.Position -= moveSpeed * _camera.Up; + + if (_keyboard.IsKeyPressed(Key.H)) + _append = true; if (_keyboard.IsKeyPressed(Key.Escape)) - _window.Close(); + _close = true; } private void OnClose() @@ -206,6 +235,7 @@ public class Snooper model.Dispose(); } _models.Clear(); + _previousSpeed = 0f; _imGui.Dispose(); _window.Dispose(); _gl.Dispose(); diff --git a/FModel/Views/Snooper/Texture.cs b/FModel/Views/Snooper/Texture.cs index 6873e0aa..630f09d8 100644 --- a/FModel/Views/Snooper/Texture.cs +++ b/FModel/Views/Snooper/Texture.cs @@ -4,6 +4,7 @@ using System.Windows; using CUE4Parse.UE4.Assets.Exports.Texture; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; +using SkiaSharp; namespace FModel.Views.Snooper; @@ -64,7 +65,7 @@ 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, UTexture2D texture2D) : this(gl, TextureType.Normal) + public unsafe Texture(GL gl, byte[] data, uint width, uint height, SKColorType colorType, UTexture2D texture2D) : this(gl, TextureType.Normal) { Type = texture2D.ExportType; Name = texture2D.Name; @@ -79,7 +80,6 @@ public class Texture : IDisposable fixed (void* d = &data[0]) { _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); _gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);