diff --git a/FModel/Views/Snooper/Camera.cs b/FModel/Views/Snooper/Camera.cs index 0409ff1b..6d68683f 100644 --- a/FModel/Views/Snooper/Camera.cs +++ b/FModel/Views/Snooper/Camera.cs @@ -13,13 +13,17 @@ public class Camera public float Yaw { get; set; } = -90f; public float Pitch { get; set; } = 0f; public float Zoom { get; set; } = 45f; - public float Speed { get; set; } = 1f; + public float Speed { get; } = 1f; + public float Near { get; } = 0.01f; + public float Far { get; } = 100f; public float AspectRatio => 16f / 9f; - public Camera(Vector3 position, Vector3 direction, float speed) + public Camera(Vector3 position, Vector3 direction, float near, float far, float speed) { Position = position; Direction = direction; + Near = near; + Far = far; Speed = speed; // trigonometric math to calculate the cam's yaw/pitch based on position and direction to look @@ -52,7 +56,7 @@ public class Camera public Matrix4x4 GetProjectionMatrix() { - return Matrix4x4.CreatePerspectiveFieldOfView(Helper.DegreesToRadians(Zoom), AspectRatio, 0.1f, 100.0f); + return Matrix4x4.CreatePerspectiveFieldOfView(Helper.DegreesToRadians(Zoom), AspectRatio, Near, Far); } public void CalculateDirection() diff --git a/FModel/Views/Snooper/Grid.cs b/FModel/Views/Snooper/Grid.cs index 9ef3788b..0e6a2e3c 100644 --- a/FModel/Views/Snooper/Grid.cs +++ b/FModel/Views/Snooper/Grid.cs @@ -51,8 +51,8 @@ public class Grid : IDisposable _shader.SetUniform("view", camera.GetViewMatrix()); _shader.SetUniform("proj", camera.GetProjectionMatrix()); - _shader.SetUniform("uNear", -0.01f); - _shader.SetUniform("uFar", 100f); + _shader.SetUniform("uNear", camera.Near); + _shader.SetUniform("uFar", camera.Far); _gl.DrawArrays(PrimitiveType.Triangles, 0, (uint) Indices.Length); diff --git a/FModel/Views/Snooper/Model.cs b/FModel/Views/Snooper/Model.cs index 6ab314c1..a342d817 100644 --- a/FModel/Views/Snooper/Model.cs +++ b/FModel/Views/Snooper/Model.cs @@ -39,7 +39,7 @@ public class Model : IDisposable for (var s = 0; s < sections.Length; s++) { var section = sections[s]; - Sections[s] = new Section(section.MaterialName, (uint) section.NumFaces * _faceSize, section.FirstIndex, section); + Sections[s] = new Section(section.MaterialName, section.MaterialIndex, (uint) section.NumFaces * _faceSize, section.FirstIndex, section); for (uint face = 0; face < section.NumFaces; face++) { foreach (var f in _facesIndex) @@ -121,7 +121,7 @@ public class Model : IDisposable ImGui.TableHeadersRow(); for (int section = 0; section < Sections.Length; section++) { - Sections[section].Bind(section, Indices.Length); + Sections[section].Bind(Indices.Length); _gl.DrawArrays(PrimitiveType.Triangles, Sections[section].FirstFaceIndex, Sections[section].FacesCount); } ImGui.EndTable(); diff --git a/FModel/Views/Snooper/Section.cs b/FModel/Views/Snooper/Section.cs index 3a3e0d61..b2806f6a 100644 --- a/FModel/Views/Snooper/Section.cs +++ b/FModel/Views/Snooper/Section.cs @@ -1,5 +1,4 @@ using System; -using System.Numerics; using CUE4Parse.UE4.Assets.Exports.Material; using CUE4Parse.UE4.Assets.Exports.Texture; using CUE4Parse_Conversion.Meshes.PSK; @@ -22,18 +21,21 @@ public class Section : IDisposable private Texture _emissionMap; public string Name; + public int Index; public uint FacesCount; public int FirstFaceIndex; public CMaterialParams Parameters; - public Section(string name, uint facesCount, int firstFaceIndex, CMeshSection section) + public Section(string name, int index, uint facesCount, int firstFaceIndex, CMeshSection section) { Name = name; + Index = index; FacesCount = facesCount; FirstFaceIndex = firstFaceIndex; Parameters = new CMaterialParams(); if (section.Material != null && section.Material.TryLoad(out var material) && material is UMaterialInterface unrealMaterial) { + Name = unrealMaterial.Name; unrealMaterial.GetParams(Parameters); } } @@ -76,18 +78,18 @@ public class Section : IDisposable } } - public void Bind(int index, float indices) + public void Bind(float indices) { ImGui.TableNextRow(); ImGui.TableSetColumnIndex(0); - ImGui.Text(index.ToString()); + ImGui.Text(Index.ToString()); ImGui.TableSetColumnIndex(1); ImGui.Text(Name); if (ImGui.IsItemHovered()) { ImGui.BeginTooltip(); - ImGui.Text($"Faces: {FacesCount} ({Math.Floor(FacesCount / indices * 100f)}%%)"); + ImGui.Text($"Faces: {FacesCount} ({Math.Round(FacesCount / indices * 100f, 2)}%%)"); ImGui.Text($"First Face: {FirstFaceIndex}"); ImGui.Separator(); ImGui.Text($"Diffuse: ({Parameters.Diffuse?.ExportType}) {Parameters.Diffuse?.Name}"); diff --git a/FModel/Views/Snooper/Snooper.cs b/FModel/Views/Snooper/Snooper.cs index fdaf5133..50c83c07 100644 --- a/FModel/Views/Snooper/Snooper.cs +++ b/FModel/Views/Snooper/Snooper.cs @@ -80,9 +80,10 @@ public class Snooper private void SetupCamera(FBox box) { + 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, box.Max.Max() / 2f); + _camera = new Camera(position, center, 0.01f, far * 50f, far / 2f); } private void OnLoad()