diff --git a/FModel/FModel.csproj b/FModel/FModel.csproj index 01d7d569..c11e65eb 100644 --- a/FModel/FModel.csproj +++ b/FModel/FModel.csproj @@ -136,6 +136,7 @@ + diff --git a/FModel/Resources/nx.png b/FModel/Resources/nx.png index a6896403..febc439e 100644 Binary files a/FModel/Resources/nx.png and b/FModel/Resources/nx.png differ diff --git a/FModel/Resources/ny.png b/FModel/Resources/ny.png index 73349e3c..5b8af2cd 100644 Binary files a/FModel/Resources/ny.png and b/FModel/Resources/ny.png differ diff --git a/FModel/Resources/nz.png b/FModel/Resources/nz.png index 8e6b1015..fcab8840 100644 Binary files a/FModel/Resources/nz.png and b/FModel/Resources/nz.png differ diff --git a/FModel/Resources/px.png b/FModel/Resources/px.png index 74a6899d..83a20ddd 100644 Binary files a/FModel/Resources/px.png and b/FModel/Resources/px.png differ diff --git a/FModel/Resources/py.png b/FModel/Resources/py.png index c0a2d1f8..f5ddf623 100644 Binary files a/FModel/Resources/py.png and b/FModel/Resources/py.png differ diff --git a/FModel/Resources/pz.png b/FModel/Resources/pz.png index 7f825fbb..8fece6be 100644 Binary files a/FModel/Resources/pz.png and b/FModel/Resources/pz.png differ diff --git a/FModel/Views/Snooper/Skybox.cs b/FModel/Views/Snooper/Skybox.cs index 73d56dc8..c23a9797 100644 --- a/FModel/Views/Snooper/Skybox.cs +++ b/FModel/Views/Snooper/Skybox.cs @@ -12,7 +12,7 @@ public class Skybox : IDisposable private BufferObject _vbo; private VertexArrayObject _vao; - private string[] _textures = { "nx", "ny", "nz", "px", "py", "pz" }; + private string[] _textures = { "px", "nx", "py", "ny", "pz", "nz" }; private Texture _cubeMap; private Shader _shader; diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index 1c18458f..6c4bd389 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -1,5 +1,7 @@ using System; using System.Numerics; +using System.Runtime.InteropServices; +using System.Windows; using CUE4Parse.UE4.Assets.Exports; using CUE4Parse.UE4.Assets.Exports.SkeletalMesh; using CUE4Parse.UE4.Assets.Exports.StaticMesh; @@ -7,11 +9,15 @@ using CUE4Parse.UE4.Objects.Core.Math; using CUE4Parse_Conversion.Meshes; using FModel.Extensions; using ImGuiNET; +using Silk.NET.Core; using Silk.NET.Input; using Silk.NET.Maths; using Silk.NET.OpenGL; using Silk.NET.OpenGL.Extensions.ImGui; using Silk.NET.Windowing; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; namespace FModel.Views.Snooper; @@ -24,8 +30,9 @@ public class Snooper private IKeyboard _keyboard; private IMouse _mouse; private Vector2 _previousMousePosition; + private RawImage _icon; - // private Skybox _skybox; + private Skybox _skybox; private Grid _grid; private Model[] _models; @@ -35,8 +42,8 @@ public class Snooper public Snooper(UObject export) { const double ratio = .7; - var x = System.Windows.SystemParameters.MaximizedPrimaryScreenWidth; - var y = System.Windows.SystemParameters.MaximizedPrimaryScreenHeight; + var x = SystemParameters.MaximizedPrimaryScreenWidth; + var y = SystemParameters.MaximizedPrimaryScreenHeight; Width = Convert.ToInt32(x * ratio); Height = Convert.ToInt32(y * ratio); @@ -45,7 +52,22 @@ public class Snooper options.WindowBorder = WindowBorder.Hidden; options.Title = "Snooper"; options.Samples = 4; - _window = Window.Create(options); + _window = Silk.NET.Windowing.Window.Create(options); + + unsafe + { + var info = Application.GetResourceStream(new Uri("/FModel;component/Resources/materialicon.png", UriKind.Relative)); + using var image = Image.Load(info.Stream); + var memoryGroup = image.GetPixelMemoryGroup(); + Memory array = new byte[memoryGroup.TotalLength * sizeof(Rgba32)]; + var block = MemoryMarshal.Cast(array.Span); + foreach (var memory in memoryGroup) + { + memory.Span.CopyTo(block); + block = block.Slice(memory.Length); + } + _icon = new RawImage(image.Width, image.Height, array); + } _window.Load += OnLoad; _window.Update += OnUpdate; @@ -53,7 +75,7 @@ public class Snooper _window.Closing += OnClose; _window.FramebufferResize += OnFramebufferResize; - // _skybox = new Skybox(); + _skybox = new Skybox(); _grid = new Grid(); _models = new Model[1]; switch (export) @@ -90,6 +112,7 @@ public class Snooper private void OnLoad() { + _window.SetWindowIcon(ref _icon); _window.Center(); var input = _window.CreateInput(); @@ -109,7 +132,7 @@ public class Snooper _controller = new ImGuiController(_gl, _window, input); - // _skybox.Setup(_gl); + _skybox.Setup(_gl); _grid.Setup(_gl); foreach (var model in _models) @@ -130,7 +153,7 @@ public class Snooper _gl.ClearColor(0.102f, 0.102f, 0.129f, 1.0f); _gl.Clear((uint) ClearBufferMask.ColorBufferBit | (uint) ClearBufferMask.DepthBufferBit); - // _skybox.Bind(_camera); + _skybox.Bind(_camera); _grid.Bind(_camera); ImGuiExtensions.Theme(); @@ -148,7 +171,7 @@ public class Snooper ImGui.EndMenu(); } - const string text = "ESC to Exit..."; + const string text = "Press ESC to Exit..."; ImGui.SetCursorPosX(ImGui.GetWindowViewport().WorkSize.X - ImGui.CalcTextSize(text).X - 5); ImGui.TextColored(ImGuiExtensions.STYLE.Colors[(int) ImGuiCol.TextDisabled], text); @@ -235,7 +258,7 @@ public class Snooper private void OnClose() { _grid.Dispose(); - // _skybox.Dispose(); + _skybox.Dispose(); foreach (var model in _models) { model.Dispose(); diff --git a/FModel/Views/Snooper/Texture.cs b/FModel/Views/Snooper/Texture.cs index fc7c48e0..5478433c 100644 --- a/FModel/Views/Snooper/Texture.cs +++ b/FModel/Views/Snooper/Texture.cs @@ -1,7 +1,8 @@ using Silk.NET.OpenGL; using System; -using System.IO; using System.Windows; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.PixelFormats; namespace FModel.Views.Snooper; @@ -56,13 +57,19 @@ public class Texture : IDisposable for (int t = 0; t < textures.Length; t++) { var info = Application.GetResourceStream(new Uri($"/FModel;component/Resources/{textures[t]}.png", UriKind.Relative)); - var stream = new MemoryStream(); - info.Stream.CopyTo(stream); + using var img = Image.Load(info.Stream); + _gl.TexImage2D(TextureTarget.TextureCubeMapPositiveX + t, 0, InternalFormat.Rgba8, (uint) img.Width, (uint) img.Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, null); - fixed (void* d = &stream.ToArray()[0]) + img.ProcessPixelRows(accessor => { - _gl.TexImage2D(TextureTarget.TextureCubeMapPositiveX + t, 0, (int) InternalFormat.Rgb, 256, 256, 0, PixelFormat.Rgb, PixelType.UnsignedByte, d); - } + for (int y = 0; y < accessor.Height; y++) + { + fixed (void* data = accessor.GetRowSpan(y)) + { + gl.TexSubImage2D(TextureTarget.TextureCubeMapPositiveX + t, 0, 0, y, (uint) accessor.Width, 1, PixelFormat.Rgba, PixelType.UnsignedByte, data); + } + } + }); } _gl.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int) GLEnum.Linear);