1
0
mirror of synced 2024-11-28 01:10:51 +01:00

Some fixes with gfbmdl faces

This commit is contained in:
KillzXGaming 2019-12-14 21:37:17 -05:00
parent 94bcbd5822
commit 8097845a1b
3 changed files with 49 additions and 18 deletions

View File

@ -40,7 +40,9 @@ namespace FirstPlugin
{
List<ToolStripItem> Items = new List<ToolStripItem>();
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);

View File

@ -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);

View File

@ -279,14 +279,7 @@ namespace Toolbox.Library
if (vertices.Count < 3)
return;
List<int> f = new List<int>();
if (lodMeshes.Count > 0)
f = lodMeshes[DisplayLODIndex].getDisplayFace();
if (PolygonGroups.Count > 0)
{
foreach (var group in PolygonGroups)
f.AddRange(group.GetDisplayFace());
}
List<int> 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<int> f = Shapes[s].lodMeshes[DisplayLODIndex].getDisplayFace();
List<int> 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<int> f = lodMeshes[DisplayLODIndex].getDisplayFace();
List<int> 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<int> f = lodMeshes[DisplayLODIndex].getDisplayFace();
List<int> 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<int> GetFaces()
{
List<int> f = new List<int>();
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;