Check determinant to prevent singular matrix issue
This commit is contained in:
parent
7238de5d37
commit
db13c0d8b7
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -909,19 +909,22 @@ namespace Bfres.Structs
|
|||||||
{
|
{
|
||||||
var skel = GetParentModel().Skeleton;
|
var skel = GetParentModel().Skeleton;
|
||||||
Matrix4 trans = Matrix4.Identity;
|
Matrix4 trans = Matrix4.Identity;
|
||||||
|
|
||||||
if (IsSingleBind)
|
if (IsSingleBind)
|
||||||
{
|
{
|
||||||
if (BoneIndex >= skel.Node_Array.Length || BoneIndex == -1)
|
if (BoneIndex >= skel.Node_Array.Length || BoneIndex == -1)
|
||||||
return position;
|
return position;
|
||||||
|
|
||||||
var bone = skel.bones[skel.Node_Array[BoneIndex]];
|
var bone = skel.bones[skel.Node_Array[BoneIndex]];
|
||||||
trans = bone.invert;
|
|
||||||
|
if (trans.Determinant != 0)
|
||||||
|
trans = bone.invert;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var bone = skel.bones[BoneIndex];
|
var bone = skel.bones[BoneIndex];
|
||||||
trans = bone.invert;
|
|
||||||
|
if (trans.Determinant != 0)
|
||||||
|
trans = bone.invert;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsPos)
|
if (IsPos)
|
||||||
@ -1090,8 +1093,8 @@ namespace Bfres.Structs
|
|||||||
if (VertexSkinCount == 1 && vtx.boneIds.Count > 0)
|
if (VertexSkinCount == 1 && vtx.boneIds.Count > 0)
|
||||||
boneId = vtx.boneIds[0];
|
boneId = vtx.boneIds[0];
|
||||||
|
|
||||||
// vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
|
vtx.pos = TransformLocal(vtx.pos, boneId, VertexSkinCount == 1);
|
||||||
// vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
|
vtx.nrm = TransformLocal(vtx.nrm, boneId, VertexSkinCount == 1, false);
|
||||||
}
|
}
|
||||||
//Console.WriteLine($"Weight count {vtx.boneWeights.Count}");
|
//Console.WriteLine($"Weight count {vtx.boneWeights.Count}");
|
||||||
//Console.WriteLine($"Index count {vtx.boneIds.Count}");
|
//Console.WriteLine($"Index count {vtx.boneIds.Count}");
|
||||||
|
@ -296,7 +296,10 @@ namespace FirstPlugin
|
|||||||
Matrix4 camMat = previewScale * control.mtxCam * control.mtxProj;
|
Matrix4 camMat = previewScale * control.mtxCam * control.mtxProj;
|
||||||
|
|
||||||
Matrix4 sphereMatrix = camMat;
|
Matrix4 sphereMatrix = camMat;
|
||||||
sphereMatrix.Invert();
|
|
||||||
|
if (sphereMatrix.Determinant != 0)
|
||||||
|
sphereMatrix.Invert();
|
||||||
|
|
||||||
sphereMatrix.Transpose();
|
sphereMatrix.Transpose();
|
||||||
shader.SetMatrix4x4("sphereMatrix", ref sphereMatrix);
|
shader.SetMatrix4x4("sphereMatrix", ref sphereMatrix);
|
||||||
|
|
||||||
@ -308,7 +311,10 @@ namespace FirstPlugin
|
|||||||
shader.SetVector3("difLightColor", new Vector3(1));
|
shader.SetVector3("difLightColor", new Vector3(1));
|
||||||
shader.SetVector3("ambLightColor", 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);
|
Vector3 lightDirection = new Vector3(0f, 0f, -1f);
|
||||||
|
|
||||||
//Todo. Maybe change direction via AAMP file (configs shader data)
|
//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++)
|
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]);
|
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;
|
Matrix4 transform = fmdl.Skeleton.bones[fmdl.Skeleton.Node_Array[i]].invert * fmdl.Skeleton.bones[fmdl.Skeleton.Node_Array[i]].Transform;
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user