diff --git a/FModel/Framework/ImGuiController.cs b/FModel/Framework/ImGuiController.cs
index d3a6a186..adb766fe 100644
--- a/FModel/Framework/ImGuiController.cs
+++ b/FModel/Framework/ImGuiController.cs
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Numerics;
using System.Runtime.CompilerServices;
using ImGuiNET;
using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
using ErrorCode = OpenTK.Graphics.OpenGL4.ErrorCode;
@@ -453,7 +453,7 @@ outputColor = color * texture(in_fontTexture, texCoord);
// Setup orthographic projection matrix into our constant buffer
ImGuiIOPtr io = ImGui.GetIO();
- Matrix4 mvp = Matrix4.CreateOrthographicOffCenter(
+ var mvp = OpenTK.Mathematics.Matrix4.CreateOrthographicOffCenter(
0.0f,
io.DisplaySize.X,
io.DisplaySize.Y,
diff --git a/FModel/Resources/pointlight.png b/FModel/Resources/pointlight.png
index 7360e2b1..c37e2990 100644
Binary files a/FModel/Resources/pointlight.png and b/FModel/Resources/pointlight.png differ
diff --git a/FModel/Resources/spotlight.png b/FModel/Resources/spotlight.png
index 83b0e048..260952e6 100644
Binary files a/FModel/Resources/spotlight.png and b/FModel/Resources/spotlight.png differ
diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs
index 4f425308..c2288177 100644
--- a/FModel/ViewModels/CUE4ParseViewModel.cs
+++ b/FModel/ViewModels/CUE4ParseViewModel.cs
@@ -41,7 +41,6 @@ using FModel.Views;
using FModel.Views.Resources.Controls;
using FModel.Views.Snooper;
using Newtonsoft.Json;
-using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using Serilog;
@@ -89,7 +88,7 @@ public class CUE4ParseViewModel : ViewModel
return _snooper ??= new Snooper(GameWindowSettings.Default,
new NativeWindowSettings
{
- Size = new Vector2i(
+ Size = new OpenTK.Mathematics.Vector2i(
Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenWidth * .75),
Convert.ToInt32(SystemParameters.MaximizedPrimaryScreenHeight * .85)),
NumberOfSamples = Constants.SAMPLES_COUNT,
diff --git a/FModel/Views/Snooper/Camera.cs b/FModel/Views/Snooper/Camera.cs
index 0f783ce0..2672d2af 100644
--- a/FModel/Views/Snooper/Camera.cs
+++ b/FModel/Views/Snooper/Camera.cs
@@ -1,6 +1,6 @@
using System;
+using System.Numerics;
using ImGuiNET;
-using OpenTK.Mathematics;
namespace FModel.Views.Snooper;
@@ -68,54 +68,14 @@ public class Camera
Direction = Vector3.Normalize(direction);
}
- public Matrix4 GetViewMatrix()
+ public Matrix4x4 GetViewMatrix()
{
- return Matrix4.LookAt(Position, Position + Direction, Up);
+ return Matrix4x4.CreateLookAt(Position, Position + Direction, Up);
}
- public Matrix4 GetProjectionMatrix()
+ public Matrix4x4 GetProjectionMatrix()
{
- return CreatePerspectiveFieldOfView(Helper.DegreesToRadians(Zoom), AspectRatio, Near, Far);
- }
-
- ///
- /// OpenTK function causes a gap between the faded out grid & the skybox
- /// so we use the System.Numerics function instead with OpenTK types
- ///
- private Matrix4 CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance)
- {
- if (fieldOfView is <= 0.0f or >= MathF.PI)
- throw new ArgumentOutOfRangeException(nameof(fieldOfView));
-
- if (nearPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- if (farPlaneDistance <= 0.0f)
- throw new ArgumentOutOfRangeException(nameof(farPlaneDistance));
-
- if (nearPlaneDistance >= farPlaneDistance)
- throw new ArgumentOutOfRangeException(nameof(nearPlaneDistance));
-
- float yScale = 1.0f / MathF.Tan(fieldOfView * 0.5f);
- float xScale = yScale / aspectRatio;
-
- Matrix4 result = Matrix4.Zero;
-
- result.M11 = xScale;
- result.M12 = result.M13 = result.M14 = 0.0f;
-
- result.M22 = yScale;
- result.M21 = result.M23 = result.M24 = 0.0f;
-
- result.M31 = result.M32 = 0.0f;
- float negFarRange = float.IsPositiveInfinity(farPlaneDistance) ? -1.0f : farPlaneDistance / (nearPlaneDistance - farPlaneDistance);
- result.M33 = negFarRange;
- result.M34 = -1.0f;
-
- result.M41 = result.M42 = result.M44 = 0.0f;
- result.M43 = nearPlaneDistance * negFarRange;
-
- return result;
+ return Matrix4x4.CreatePerspectiveFieldOfView(Helper.DegreesToRadians(Zoom), AspectRatio, Near, Far);
}
private const float _step = 0.01f;
diff --git a/FModel/Views/Snooper/FramebufferObject.cs b/FModel/Views/Snooper/FramebufferObject.cs
index 1d239ec2..84d65a11 100644
--- a/FModel/Views/Snooper/FramebufferObject.cs
+++ b/FModel/Views/Snooper/FramebufferObject.cs
@@ -1,6 +1,5 @@
using System;
using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
namespace FModel.Views.Snooper;
@@ -33,7 +32,7 @@ public class FramebufferObject : IDisposable
-1.0f, 1.0f, 0.0f, 1.0f
};
- public FramebufferObject(Vector2i size)
+ public FramebufferObject(OpenTK.Mathematics.Vector2i size)
{
_width = size.X;
_height = size.Y;
diff --git a/FModel/Views/Snooper/Grid.cs b/FModel/Views/Snooper/Grid.cs
index 0190c7bf..3d79adbd 100644
--- a/FModel/Views/Snooper/Grid.cs
+++ b/FModel/Views/Snooper/Grid.cs
@@ -1,6 +1,6 @@
using System;
+using System.Numerics;
using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
namespace FModel.Views.Snooper;
@@ -39,7 +39,7 @@ public class Grid : IDisposable
_vao.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0); // position
}
- public void Render(Matrix4 viewMatrix, Matrix4 projMatrix, float near, float far)
+ public void Render(Matrix4x4 viewMatrix, Matrix4x4 projMatrix, float near, float far)
{
GL.Disable(EnableCap.DepthTest);
_vao.Bind();
diff --git a/FModel/Views/Snooper/PickingTexture.cs b/FModel/Views/Snooper/PickingTexture.cs
index 1033a49d..4c459987 100644
--- a/FModel/Views/Snooper/PickingTexture.cs
+++ b/FModel/Views/Snooper/PickingTexture.cs
@@ -2,8 +2,7 @@
using System.Collections.Generic;
using CUE4Parse.UE4.Objects.Core.Misc;
using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
-using Vector2 = System.Numerics.Vector2;
+using System.Numerics;
namespace FModel.Views.Snooper;
@@ -53,7 +52,7 @@ public class PickingTexture : IDisposable
Bind(0);
}
- public void Render(Matrix4 viewMatrix, Matrix4 projMatrix, IDictionary models)
+ public void Render(Matrix4x4 viewMatrix, Matrix4x4 projMatrix, IDictionary models)
{
Bind();
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs
index 79e97c86..487e19c1 100644
--- a/FModel/Views/Snooper/Renderer.cs
+++ b/FModel/Views/Snooper/Renderer.cs
@@ -14,7 +14,6 @@ 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;
diff --git a/FModel/Views/Snooper/Shader.cs b/FModel/Views/Snooper/Shader.cs
index fde49a71..54c25eb6 100644
--- a/FModel/Views/Snooper/Shader.cs
+++ b/FModel/Views/Snooper/Shader.cs
@@ -1,14 +1,16 @@
using System;
+using System.Collections.Generic;
using System.IO;
+using System.Numerics;
using System.Reflection;
using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
namespace FModel.Views.Snooper;
public class Shader : IDisposable
{
private readonly int _handle;
+ private readonly Dictionary _uniformsLocation = new ();
public Shader() : this("default") {}
@@ -54,17 +56,17 @@ public class Shader : IDisposable
GL.UseProgram(_handle);
}
- public void Render(Matrix4 viewMatrix, Vector3 viewPos, Vector3 viewDir, Matrix4 projMatrix)
+ public void Render(Matrix4x4 viewMatrix, Vector3 viewPos, Vector3 viewDir, Matrix4x4 projMatrix)
{
Render(viewMatrix, viewPos, projMatrix);
SetUniform("uViewDir", viewDir);
}
- public void Render(Matrix4 viewMatrix, Vector3 viewPos, Matrix4 projMatrix)
+ public void Render(Matrix4x4 viewMatrix, Vector3 viewPos, Matrix4x4 projMatrix)
{
Render(viewMatrix, projMatrix);
SetUniform("uViewPos", viewPos);
}
- public void Render(Matrix4 viewMatrix, Matrix4 projMatrix)
+ public void Render(Matrix4x4 viewMatrix, Matrix4x4 projMatrix)
{
Use();
SetUniform("uView", viewMatrix);
@@ -73,61 +75,51 @@ public class Shader : IDisposable
public void SetUniform(string name, int value)
{
- int location = GL.GetUniformLocation(_handle, name);
- ThrowIfNotFound(location, name);
- GL.Uniform1(location, value);
+ GL.Uniform1(GetUniformLocation(name), value);
}
- public unsafe void SetUniform(string name, Matrix4 value) => UniformMatrix4(name, (float*) &value);
- public unsafe void SetUniform(string name, System.Numerics.Matrix4x4 value) => UniformMatrix4(name, (float*) &value);
+ public unsafe void SetUniform(string name, Matrix4x4 value) => UniformMatrix4(name, (float*) &value);
public unsafe void UniformMatrix4(string name, float* value)
{
- //A new overload has been created for setting a uniform so we can use the transform in our shader.
- int location = GL.GetUniformLocation(_handle, name);
- ThrowIfNotFound(location, name);
- GL.UniformMatrix4(location, 1, false, value);
+ GL.UniformMatrix4(GetUniformLocation(name), 1, false, value);
}
public void SetUniform(string name, bool value) => SetUniform(name, Convert.ToUInt32(value));
public void SetUniform(string name, uint value)
{
- int location = GL.GetUniformLocation(_handle, name);
- ThrowIfNotFound(location, name);
- GL.Uniform1(location, value);
+ GL.Uniform1(GetUniformLocation(name), value);
}
public void SetUniform(string name, float value)
{
- int location = GL.GetUniformLocation(_handle, name);
- ThrowIfNotFound(location, name);
- GL.Uniform1(location, value);
+ GL.Uniform1(GetUniformLocation(name), value);
}
public void SetUniform(string name, Vector3 value) => SetUniform3(name, value.X, value.Y, value.Z);
- public void SetUniform(string name, System.Numerics.Vector3 value) => SetUniform3(name, value.X, value.Y, value.Z);
public void SetUniform3(string name, float x, float y, float z)
{
- int location = GL.GetUniformLocation(_handle, name);
- ThrowIfNotFound(location, name);
- GL.Uniform3(location, x, y, z);
+ GL.Uniform3(GetUniformLocation(name), x, y, z);
}
public void SetUniform(string name, Vector4 value) => SetUniform4(name, value.X, value.Y, value.Z, value.W);
- public void SetUniform(string name, System.Numerics.Vector4 value) => SetUniform4(name, value.X, value.Y, value.Z, value.W);
public void SetUniform4(string name, float x, float y, float z, float w)
{
- int location = GL.GetUniformLocation(_handle, name);
- ThrowIfNotFound(location, name);
- GL.Uniform4(location, x, y, z, w);
+ GL.Uniform4(GetUniformLocation(name), x, y, z, w);
}
- private void ThrowIfNotFound(int location, string name)
+ private int GetUniformLocation(string name)
{
- if (location == -1)
+ if (!_uniformsLocation.TryGetValue(name, out int location))
{
- throw new Exception($"{name} uniform not found on shader.");
+ location = GL.GetUniformLocation(_handle, name);
+ _uniformsLocation.Add(name, location);
+ if (location == -1)
+ {
+ throw new Exception($"{name} uniform not found on shader.");
+ }
}
+ return location;
}
public void Dispose()
diff --git a/FModel/Views/Snooper/Skeleton.cs b/FModel/Views/Snooper/Skeleton.cs
index 57c23577..33313d0e 100644
--- a/FModel/Views/Snooper/Skeleton.cs
+++ b/FModel/Views/Snooper/Skeleton.cs
@@ -30,17 +30,23 @@ public class Skeleton : IDisposable
continue;
var transform = Transform.Identity;
- for (int j = 0; j <= boneIndex; j++)
+ while (boneIndex > -1)
{
- var t = RefSkel.ReferenceSkeleton.FinalRefBonePose[j].Inverse();
- (t.Translation.X, t.Translation.Z, t.Translation.Y) = (-t.Translation.Z, -t.Translation.Y, -t.Translation.X);
- var matrix = Matrix4x4.CreateScale(t.Scale3D.ToMapVector());
- // matrix *= Matrix4x4.CreateFromQuaternion(t.Rotation);
- matrix *= Matrix4x4.CreateTranslation(t.Translation * Constants.SCALE_DOWN_RATIO);
+ var t = RefSkel.ReferenceSkeleton.FinalRefBonePose[boneIndex];
+ transform.Position += t.Rotation.RotateVector(t.Translation.ToMapVector()) * Constants.SCALE_DOWN_RATIO;
- // Console.WriteLine($@"{t.Translation}");
- transform.Relation *= matrix;
+ boneIndex = RefSkel.ReferenceSkeleton.FinalRefBoneInfo[boneIndex].ParentIndex;
}
+ // for (int j = 0; j <= 3; j++)
+ // {
+ // var t = RefSkel.ReferenceSkeleton.FinalRefBonePose[j];
+ // // var matrix = Matrix4x4.CreateScale(t.Scale3D.ToMapVector());
+ // // matrix *= Matrix4x4.CreateFromQuaternion(t.Rotation);
+ // transform.Position += t.Rotation.UnrotateVector(t.Translation.ToMapVector()) * Constants.SCALE_DOWN_RATIO;
+ //
+ // // Console.WriteLine($@"{t.Translation}");
+ // // transform.Relation *= matrix;
+ // }
Sockets[i] = new Socket(socket, transform);
}
diff --git a/FModel/Views/Snooper/Skybox.cs b/FModel/Views/Snooper/Skybox.cs
index 424c593b..778df711 100644
--- a/FModel/Views/Snooper/Skybox.cs
+++ b/FModel/Views/Snooper/Skybox.cs
@@ -1,6 +1,6 @@
using System;
+using System.Numerics;
using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
namespace FModel.Views.Snooper;
@@ -79,7 +79,7 @@ public class Skybox : IDisposable
_vao.VertexAttributePointer(0, 3, VertexAttribPointerType.Float, 3, 0); // position
}
- public void Render(Matrix4 viewMatrix, Matrix4 projMatrix)
+ public void Render(Matrix4x4 viewMatrix, Matrix4x4 projMatrix)
{
GL.DepthFunc(DepthFunction.Lequal);
diff --git a/FModel/Views/Snooper/SnimGui.cs b/FModel/Views/Snooper/SnimGui.cs
index 4a41a3c5..2229018d 100644
--- a/FModel/Views/Snooper/SnimGui.cs
+++ b/FModel/Views/Snooper/SnimGui.cs
@@ -3,10 +3,8 @@ using System.Collections.Generic;
using CUE4Parse.UE4.Objects.Core.Misc;
using FModel.Framework;
using ImGuiNET;
-using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
-using Vector2 = System.Numerics.Vector2;
-using Vector4 = System.Numerics.Vector4;
+using System.Numerics;
namespace FModel.Views.Snooper;
@@ -88,7 +86,7 @@ public class SnimGui
}
}
- private void DrawDockSpace(Vector2i size)
+ private void DrawDockSpace(OpenTK.Mathematics.Vector2i size)
{
const ImGuiWindowFlags flags =
ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoDocking |
diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs
index d5d5718f..f12d852f 100644
--- a/FModel/Views/Snooper/Snooper.cs
+++ b/FModel/Views/Snooper/Snooper.cs
@@ -1,10 +1,10 @@
using System.ComponentModel;
+using System.Numerics;
using System.Threading;
using System.Windows;
using CUE4Parse.UE4.Assets.Exports;
using ImGuiNET;
using OpenTK.Graphics.OpenGL4;
-using OpenTK.Mathematics;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using OpenTK.Windowing.GraphicsLibraryFramework;
@@ -78,7 +78,7 @@ public class Snooper : GameWindow
base.OnLoad();
CenterWindow();
- GL.ClearColor(Color4.Black);
+ GL.ClearColor(OpenTK.Mathematics.Color4.Black);
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.DepthTest);
GL.Enable(EnableCap.Multisample);
diff --git a/FModel/Views/Snooper/Socket.cs b/FModel/Views/Snooper/Socket.cs
index a9c1c6b2..1b6e1e8f 100644
--- a/FModel/Views/Snooper/Socket.cs
+++ b/FModel/Views/Snooper/Socket.cs
@@ -13,11 +13,10 @@ public class Socket : IDisposable
{
Name = socket.SocketName.Text;
Bone = socket.BoneName.Text;
- Transform = Transform.Identity;
- Transform.Relation = transform.Matrix;
- Transform.Position = socket.RelativeLocation.ToMapVector() * Constants.SCALE_DOWN_RATIO;
- Transform.Rotation = socket.RelativeRotation;
- Transform.Scale = socket.RelativeScale.ToMapVector();
+ Transform = transform;
+ // Transform.Relation = transform.Matrix;
+ // Transform.Position = socket.RelativeRotation.RotateVector(socket.RelativeLocation.ToMapVector()) * Constants.SCALE_DOWN_RATIO;
+ // Transform.Scale = socket.RelativeScale.ToMapVector();
}
public void Dispose()