From 946d38c87b430c1fe978c6bd5407db0e72a96358 Mon Sep 17 00:00:00 2001 From: Asval Date: Sun, 6 Aug 2023 20:02:21 +0200 Subject: [PATCH] it is about time the update thread gets fixed --- CUE4Parse | 2 +- FModel/FModel.csproj | 10 ++--- FModel/MainWindow.xaml.cs | 9 ++-- FModel/ViewModels/CUE4ParseViewModel.cs | 2 +- FModel/Views/Snooper/Models/Grid.cs | 3 +- FModel/Views/Snooper/Models/Skybox.cs | 3 +- FModel/Views/Snooper/Renderer.cs | 56 ++++++++++++++++++------- FModel/Views/Snooper/SnimGui.cs | 2 +- FModel/Views/Snooper/Snooper.cs | 55 ++++++++---------------- 9 files changed, 75 insertions(+), 67 deletions(-) diff --git a/CUE4Parse b/CUE4Parse index f9bff17d..4f5d66ac 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit f9bff17d172e72184678211c567f708e25bb3f68 +Subproject commit 4f5d66ac7cacb0aad373a9f19c203569f1c38a93 diff --git a/FModel/FModel.csproj b/FModel/FModel.csproj index 7f2f84df..07c2fded 100644 --- a/FModel/FModel.csproj +++ b/FModel/FModel.csproj @@ -135,19 +135,19 @@ - + - - + + - + - + diff --git a/FModel/MainWindow.xaml.cs b/FModel/MainWindow.xaml.cs index 9f3c84d1..2c486824 100644 --- a/FModel/MainWindow.xaml.cs +++ b/FModel/MainWindow.xaml.cs @@ -83,9 +83,12 @@ public partial class MainWindow ).ConfigureAwait(false); #if DEBUG - // await _threadWorkerView.Begin(cancellationToken => - // _applicationView.CUE4Parse.Extract(cancellationToken, - // "fortnitegame/Content/Characters/Player/Female/Medium/Bodies/F_MED_Ballerina/Meshes/F_MED_Ballerina.uasset")); + await _threadWorkerView.Begin(cancellationToken => + _applicationView.CUE4Parse.Extract(cancellationToken, + "Hk_project/Content/Character/Cat/Mesh/SKM_Cat.uasset")); + await _threadWorkerView.Begin(cancellationToken => + _applicationView.CUE4Parse.Extract(cancellationToken, + "Hk_project/Content/Animation/CAT/Idle/CAT_SitBalledStrechingToStand_Idle.uasset")); #endif } diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index d97e85fb..52ec612f 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -96,7 +96,7 @@ public class CUE4ParseViewModel : ViewModel var scale = ImGuiController.GetDpiScale(); var htz = Snooper.GetMaxRefreshFrequency(); return _snooper = new Snooper( - new GameWindowSettings { RenderFrequency = htz, UpdateFrequency = htz }, + new GameWindowSettings { UpdateFrequency = htz }, new NativeWindowSettings { Size = new OpenTK.Mathematics.Vector2i( diff --git a/FModel/Views/Snooper/Models/Grid.cs b/FModel/Views/Snooper/Models/Grid.cs index deef2f80..8d6b6814 100644 --- a/FModel/Views/Snooper/Models/Grid.cs +++ b/FModel/Views/Snooper/Models/Grid.cs @@ -45,16 +45,17 @@ public class Grid : IDisposable { GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.DepthTest); + _vao.Bind(); _shader.Use(); - _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); GL.Enable(EnableCap.CullFace); } diff --git a/FModel/Views/Snooper/Models/Skybox.cs b/FModel/Views/Snooper/Models/Skybox.cs index 9ff8c53f..af04e3b5 100644 --- a/FModel/Views/Snooper/Models/Skybox.cs +++ b/FModel/Views/Snooper/Models/Skybox.cs @@ -87,8 +87,6 @@ public class Skybox : IDisposable GL.DepthFunc(DepthFunction.Lequal); _vao.Bind(); - - _cubeMap.Bind(TextureUnit.Texture0); _shader.Use(); viewMatrix.M41 = 0; @@ -97,6 +95,7 @@ public class Skybox : IDisposable _shader.SetUniform("uView", viewMatrix); _shader.SetUniform("uProjection", projMatrix); + _cubeMap.Bind(TextureUnit.Texture0); _shader.SetUniform("cubemap", 0); GL.DrawArrays(PrimitiveType.Triangles, 0, 36); diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index 0d7fc426..e856e4c5 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -24,6 +24,7 @@ using FModel.Views.Snooper.Buffers; using FModel.Views.Snooper.Lights; using FModel.Views.Snooper.Models; using FModel.Views.Snooper.Shading; +using OpenTK.Windowing.GraphicsLibraryFramework; namespace FModel.Views.Snooper; @@ -215,7 +216,7 @@ public class Renderer : IDisposable Options.SetupModelsAndLights(); } - public void Render(float deltaSeconds) + public void Render() { var viewMatrix = CameraOp.GetViewMatrix(); var projMatrix = CameraOp.GetProjectionMatrix(); @@ -227,23 +228,9 @@ public class Renderer : IDisposable for (int i = 0; i < 5; i++) _shader.SetUniform($"bVertexColors[{i}]", i == (int) Color); - // update animations - if (Options.Animations.Count > 0) Options.Tracker.Update(deltaSeconds); - foreach (var animation in Options.Animations) - { - animation.TimeCalculation(Options.Tracker.ElapsedTime); - foreach (var guid in animation.AttachedModels.Where(guid => Options.Models[guid].HasSkeleton)) - { - Options.Models[guid].Skeleton.UpdateAnimationMatrices( - animation.CurrentSequence, animation.FrameInSequence, - animation.NextFrameInSequence, animation.LerpAmount); - } - } - // render model pass foreach (var model in Options.Models.Values) { - model.UpdateMatrices(Options); if (!model.Show) continue; model.Render(_shader); } @@ -272,6 +259,45 @@ public class Renderer : IDisposable Picking.Render(viewMatrix, projMatrix, Options.Models); } + public void Update(Snooper wnd, float deltaSeconds) + { + if (Options.Animations.Count > 0) Options.Tracker.Update(deltaSeconds); + foreach (var animation in Options.Animations) + { + animation.TimeCalculation(Options.Tracker.ElapsedTime); + foreach (var guid in animation.AttachedModels.Where(guid => Options.Models[guid].HasSkeleton)) + { + Options.Models[guid].Skeleton.UpdateAnimationMatrices( + animation.CurrentSequence, animation.FrameInSequence, + animation.NextFrameInSequence, animation.LerpAmount); + } + } + + foreach (var model in Options.Models.Values) + { + model.UpdateMatrices(Options); + } + + CameraOp.Modify(wnd.KeyboardState, deltaSeconds); + + if (wnd.KeyboardState.IsKeyPressed(Keys.Z) && + Options.TryGetModel(out var selectedModel) && + selectedModel.HasSkeleton) + { + Options.RemoveAnimations(); + Options.AnimateMesh(true); + wnd.WindowShouldClose(true, false); + } + if (wnd.KeyboardState.IsKeyPressed(Keys.Space)) + Options.Tracker.IsPaused = !Options.Tracker.IsPaused; + if (wnd.KeyboardState.IsKeyPressed(Keys.Delete)) + Options.RemoveModel(Options.SelectedModel); + if (wnd.KeyboardState.IsKeyPressed(Keys.H)) + wnd.WindowShouldClose(true, false); + if (wnd.KeyboardState.IsKeyPressed(Keys.Escape)) + wnd.WindowShouldClose(true, true); + } + private void LoadStaticMesh(UStaticMesh original) { var guid = original.LightingGuid; diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs index 81a775c3..ad40674d 100644 --- a/FModel/Views/Snooper/SnimGui.cs +++ b/FModel/Views/Snooper/SnimGui.cs @@ -89,7 +89,7 @@ public class SnimGui public void Render(Snooper s) { Controller.SemiBold(); - DrawDockSpace(s.Size); + DrawDockSpace(s.ClientSize); SectionWindow("Material Inspector", s.Renderer, DrawMaterialInspector, false); AnimationWindow("Timeline", s.Renderer, (icons, tracker, animations) => diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index f4749be4..7a2711d6 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Windows.Forms; using CUE4Parse.UE4.Assets.Exports; using FModel.Views.Snooper.Buffers; -using ImGuiNET; using OpenTK.Graphics.OpenGL4; using OpenTK.Windowing.Common; using OpenTK.Windowing.Common.Input; @@ -14,7 +13,6 @@ using OpenTK.Windowing.GraphicsLibraryFramework; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using Application = System.Windows.Application; -using Keys = OpenTK.Windowing.GraphicsLibraryFramework.Keys; namespace FModel.Views.Snooper; @@ -112,33 +110,41 @@ public class Snooper : GameWindow _init = true; } + private void ClearWhatHasBeenDrawn() + { + GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); + GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); + } + protected override void OnRenderFrame(FrameEventArgs args) { base.OnRenderFrame(args); if (!IsVisible) return; - var delta = (float) args.Time; - ClearWhatHasBeenDrawn(); // clear window background - _gui.Controller.Update(this, delta); - _gui.Render(this); - Framebuffer.Bind(); // switch to viewport background ClearWhatHasBeenDrawn(); // clear viewport background - Renderer.Render(delta); + Renderer.Render(); // render everything Framebuffer.BindMsaa(); Framebuffer.Bind(0); // switch to window background + _gui.Render(this); // render UI SwapBuffers(); } - private void ClearWhatHasBeenDrawn() + protected override void OnUpdateFrame(FrameEventArgs e) { - GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); - GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); + base.OnUpdateFrame(e); + if (!IsVisible) + return; + + var delta = (float) e.Time; + + _gui.Controller.Update(this, delta); + Renderer.Update(this, delta); } protected override void OnTextInput(TextInputEventArgs e) @@ -150,33 +156,6 @@ public class Snooper : GameWindow _gui.Controller.PressChar((char) e.Unicode); } - protected override void OnUpdateFrame(FrameEventArgs e) - { - base.OnUpdateFrame(e); - if (!IsVisible || ImGui.GetIO().WantTextInput) - return; - - var delta = (float) e.Time; - Renderer.CameraOp.Modify(KeyboardState, delta); - - if (KeyboardState.IsKeyPressed(Keys.Z) && - Renderer.Options.TryGetModel(out var selectedModel) && - selectedModel.HasSkeleton) - { - Renderer.Options.RemoveAnimations(); - Renderer.Options.AnimateMesh(true); - WindowShouldClose(true, false); - } - if (KeyboardState.IsKeyPressed(Keys.Space)) - Renderer.Options.Tracker.IsPaused = !Renderer.Options.Tracker.IsPaused; - if (KeyboardState.IsKeyPressed(Keys.Delete)) - Renderer.Options.RemoveModel(Renderer.Options.SelectedModel); - if (KeyboardState.IsKeyPressed(Keys.H)) - WindowShouldClose(true, false); - if (KeyboardState.IsKeyPressed(Keys.Escape)) - WindowShouldClose(true, true); - } - protected override void OnResize(ResizeEventArgs e) { base.OnResize(e);