From 8097845a1bc1d4127b7b206fe26a446e3e931f33 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Sat, 14 Dec 2019 21:37:17 -0500 Subject: [PATCH] Some fixes with gfbmdl faces --- .../Pokemon/GFLX/GFBMDL/GFLXMesh.cs | 21 ++++++++++++ .../GFLX/GFBMDL/GFLXMeshBufferHelper.cs | 12 ++++--- .../Generics/GenericObject.cs | 34 +++++++++++-------- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMesh.cs b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMesh.cs index 9c95f2d7..9f38cf76 100644 --- a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMesh.cs +++ b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMesh.cs @@ -40,7 +40,9 @@ namespace FirstPlugin { List Items = new List(); var uvMenu = new ToolStripMenuItem("UVs"); + var normalsMenu = new ToolStripMenuItem("Normals"); Items.Add(uvMenu); + Items.Add(normalsMenu); Items.Add(new ToolStripMenuItem("Recalculate Bitangents", null, CalculateTangentBitangenAction, Keys.Control | Keys.T)); uvMenu.DropDownItems.Add(new ToolStripMenuItem("Flip Vertical", null, FlipVerticalAction, Keys.Control | Keys.V)); @@ -48,7 +50,10 @@ namespace FirstPlugin var colorMenu = new ToolStripMenuItem("Vertex Colors"); colorMenu.DropDownItems.Add(new ToolStripMenuItem("Set Color", null, SetVertexColorDialog, Keys.Control | Keys.C)); colorMenu.DropDownItems.Add(new ToolStripMenuItem("Convert Normals", null, SetVertexColorNormals, Keys.Control | Keys.N)); + normalsMenu.DropDownItems.Add(new ToolStripMenuItem("Recalculate", null, RecalculateNormals, Keys.Control | Keys.R)); + normalsMenu.DropDownItems.Add(new ToolStripMenuItem("Smooth", null, SmoothNormals, Keys.Control | Keys.S)); + Items.Add(colorMenu); return Items.ToArray(); @@ -101,6 +106,22 @@ namespace FirstPlugin UpdateMesh(); } + private void RecalculateNormals(object sender, EventArgs args) + { + Cursor.Current = Cursors.WaitCursor; + CalculateNormals(); + UpdateMesh(); + Cursor.Current = Cursors.Default; + } + + private void SmoothNormals(object sender, EventArgs args) + { + Cursor.Current = Cursors.WaitCursor; + SmoothNormals(); + UpdateMesh(); + Cursor.Current = Cursors.Default; + } + private void CalculateTangentBitangenAction(object sender, EventArgs args) { this.CalculateTangentBitangent(false); diff --git a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs index 2e4fe44a..e42a398b 100644 --- a/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs +++ b/File_Format_Library/FileFormats/Pokemon/GFLX/GFBMDL/GFLXMeshBufferHelper.cs @@ -51,10 +51,14 @@ namespace FirstPlugin values.Add(mesh.vertices[v].pos.Z); break; case VertexType.Normal: - values.Add(mesh.vertices[v].nrm.X); - values.Add(mesh.vertices[v].nrm.Y); - values.Add(mesh.vertices[v].nrm.Z); - values.Add(mesh.vertices[v].normalW); + OpenTK.Vector4 normal = new OpenTK.Vector4(mesh.vertices[v].nrm.X, + mesh.vertices[v].nrm.Y, mesh.vertices[v].nrm.Z, + mesh.vertices[v].normalW); + + values.Add(normal.X); + values.Add(normal.Y); + values.Add(normal.Z); + values.Add(normal.W); break; case VertexType.Color1: values.Add(mesh.vertices[v].col.X * 255); diff --git a/Switch_Toolbox_Library/Generics/GenericObject.cs b/Switch_Toolbox_Library/Generics/GenericObject.cs index 1416fb9f..2c6e6148 100644 --- a/Switch_Toolbox_Library/Generics/GenericObject.cs +++ b/Switch_Toolbox_Library/Generics/GenericObject.cs @@ -279,14 +279,7 @@ namespace Toolbox.Library if (vertices.Count < 3) return; - List f = new List(); - if (lodMeshes.Count > 0) - f = lodMeshes[DisplayLODIndex].getDisplayFace(); - if (PolygonGroups.Count > 0) - { - foreach (var group in PolygonGroups) - f.AddRange(group.GetDisplayFace()); - } + List f = GetFaces(); Vector3[] tanArray = new Vector3[vertices.Count]; Vector3[] bitanArray = new Vector3[vertices.Count]; @@ -416,9 +409,9 @@ namespace Toolbox.Library Vector3[] normals = new Vector3[Shapes[s].vertices.Count]; - List f = Shapes[s].lodMeshes[DisplayLODIndex].getDisplayFace(); + List f = Shapes[s].GetFaces(); - for (int v = 0; v < Shapes[s].lodMeshes[DisplayLODIndex].displayFaceSize; v += 3) + for (int v = 0; v < f.Count; v += 3) { Vertex v1 = Shapes[s].vertices[f[v]]; Vertex v2 = Shapes[s].vertices[f[v + 1]]; @@ -498,9 +491,9 @@ namespace Toolbox.Library Vector3[] normals = new Vector3[vertices.Count]; - List f = lodMeshes[DisplayLODIndex].getDisplayFace(); + List f = GetFaces(); - for (int i = 0; i < lodMeshes[DisplayLODIndex].displayFaceSize; i += 3) + for (int i = 0; i < f.Count; i += 3) { Vertex v1 = vertices[f[i]]; Vertex v2 = vertices[f[i + 1]]; @@ -562,9 +555,9 @@ namespace Toolbox.Library for (int i = 0; i < normals.Length; i++) normals[i] = new Vector3(0, 0, 0); - List f = lodMeshes[DisplayLODIndex].getDisplayFace(); + List f = GetFaces(); - for (int i = 0; i < lodMeshes[DisplayLODIndex].displayFaceSize; i += 3) + for (int i = 0; i < f.Count; i += 3) { Vertex v1 = vertices[f[i]]; Vertex v2 = vertices[f[i + 1]]; @@ -580,6 +573,19 @@ namespace Toolbox.Library vertices[i].nrm = normals[i].Normalized(); } + private List GetFaces() + { + List f = new List(); + if (PolygonGroups.Count > 0) + { + foreach (var group in PolygonGroups) + f.AddRange(group.GetDisplayFace()); + } + else if (lodMeshes.Count > 0) + f = lodMeshes[DisplayLODIndex].getDisplayFace(); + return f; + } + private Vector3 CalculateNormal(Vertex v1, Vertex v2, Vertex v3) { Vector3 U = v2.pos - v1.pos;