Fix normals from model importing if the model's scale was transformed

This commit is contained in:
KillzXGaming 2019-04-12 16:21:00 -04:00
parent 2197414b5f
commit 4dcc523125
8 changed files with 4 additions and 13 deletions

Binary file not shown.

View file

@ -2201,15 +2201,6 @@ namespace Bfres.Structs
}
}
}
public void TransformPosition(Vector3 Position, Vector3 Rotation, Vector3 Scale)
{
Matrix4 BonePosExtra = Utils.TransformValues(Position, Rotation, Scale);
foreach (Vertex v in vertices)
{
v.pos = Vector3.TransformPosition(v.pos, BonePosExtra);
v.nrm = Vector3.TransformNormal(v.pos, BonePosExtra);
}
}
private void OpenMaterialEditor(object sender, EventArgs args)
{
FormLoader.LoadMatEditor(GetMaterial());

View file

@ -418,6 +418,8 @@ namespace Switch_Toolbox.Library
}
public List<Vertex> GetVertices(Mesh msh, Matrix4 transform, STGenericObject STobj)
{
Matrix4 NormalsTransform = Matrix4.CreateFromQuaternion(transform.ExtractRotation());
List<Vertex> vertices = new List<Vertex>();
for (int v = 0; v < msh.VertexCount; v++)
{
@ -426,7 +428,7 @@ namespace Switch_Toolbox.Library
if (msh.HasVertices)
vert.pos = Vector3.TransformPosition(AssimpHelper.FromVector(msh.Vertices[v]), transform);
if (msh.HasNormals)
vert.nrm = Vector3.TransformNormal(AssimpHelper.FromVector(msh.Normals[v]), transform);
vert.nrm = Vector3.TransformNormal(AssimpHelper.FromVector(msh.Normals[v]), NormalsTransform);
if (msh.HasTextureCoords(0))
vert.uv0 = new Vector2(msh.TextureCoordinateChannels[0][v].X, msh.TextureCoordinateChannels[0][v].Y);
if (msh.HasTextureCoords(1))

View file

@ -172,9 +172,7 @@ namespace Switch_Toolbox.Library
Matrix4 Transformation = (rotXMat * rotYMat * rotZMat) * positionMat;
foreach (Vertex v in vertices)
{
v.pos = Vector3.TransformPosition(v.pos, Transformation);
v.pos = Vector3.TransformPosition(v.pos, scaleMat);
v.pos = Vector3.TransformPosition(v.pos, scaleMat * Transformation);
v.nrm = Vector3.TransformNormal(v.nrm, Transformation);
}
}