1
0
mirror of synced 2024-12-02 19:17:24 +01:00

Check determinant to prevent singular matrix issue

This commit is contained in:
KillzXGaming 2019-03-30 17:12:08 -04:00
parent 7238de5d37
commit db13c0d8b7
7 changed files with 16 additions and 11 deletions

Binary file not shown.

View File

@ -909,19 +909,22 @@ namespace Bfres.Structs
{
var skel = GetParentModel().Skeleton;
Matrix4 trans = Matrix4.Identity;
if (IsSingleBind)
{
if (BoneIndex >= skel.Node_Array.Length || BoneIndex == -1)
return position;
var bone = skel.bones[skel.Node_Array[BoneIndex]];
trans = bone.invert;
if (trans.Determinant != 0)
trans = bone.invert;
}
else
{
var bone = skel.bones[BoneIndex];
trans = bone.invert;
if (trans.Determinant != 0)
trans = bone.invert;
}
if (IsPos)
@ -1090,8 +1093,8 @@ namespace Bfres.Structs
if (VertexSkinCount == 1 && vtx.boneIds.Count > 0)
boneId = vtx.boneIds[0];
// vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
// vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
}
//Console.WriteLine($"Weight count {vtx.boneWeights.Count}");
//Console.WriteLine($"Index count {vtx.boneIds.Count}");

View File

@ -296,7 +296,10 @@ namespace FirstPlugin
Matrix4 camMat = previewScale * control.mtxCam * control.mtxProj;
Matrix4 sphereMatrix = camMat;
sphereMatrix.Invert();
if (sphereMatrix.Determinant != 0)
sphereMatrix.Invert();
sphereMatrix.Transpose();
shader.SetMatrix4x4("sphereMatrix", ref sphereMatrix);
@ -308,7 +311,10 @@ namespace FirstPlugin
shader.SetVector3("difLightColor", new Vector3(1));
shader.SetVector3("ambLightColor", new Vector3(1));
Matrix4 invertedCamera = camMat.Inverted();
Matrix4 invertedCamera = Matrix4.Identity;
if (invertedCamera.Determinant != 0)
invertedCamera = camMat.Inverted();
Vector3 lightDirection = new Vector3(0f, 0f, -1f);
//Todo. Maybe change direction via AAMP file (configs shader data)
@ -427,10 +433,6 @@ namespace FirstPlugin
{
for (int i = 0; i < fmdl.Skeleton.Node_Array.Length; i++)
{
// if (!fmdl.Skeleton.bones[fmdl.Skeleton.Node_Array[i]].Visible)
// fshp.Checked = false;
GL.Uniform1(GL.GetUniformLocation(shader.program, String.Format("boneIds[{0}]", i)), fmdl.Skeleton.Node_Array[i]);
Matrix4 transform = fmdl.Skeleton.bones[fmdl.Skeleton.Node_Array[i]].invert * fmdl.Skeleton.bones[fmdl.Skeleton.Node_Array[i]].Transform;