1
0
mirror of synced 2025-01-31 12:23:52 +01:00

Load bone weights and indices properly for bcres

This commit is contained in:
KillzXGaming 2019-05-11 21:17:49 -04:00
parent 94554db10c
commit 3b445272db
8 changed files with 15 additions and 10 deletions

Binary file not shown.

View File

@ -241,7 +241,7 @@ namespace FirstPlugin
if (FaceGroup.SkinnningMode == SkinnningMode.Rigid)
{
Matrix4 sb = skeleton.bones[v.boneIds[0]].Transform;
Matrix4 sb = skeleton.bones[(int)FaceGroup.BoneIndexList[v.boneIds[0]]].Transform;
v.pos = Vector3.TransformPosition(v.pos, sb);
v.nrm = Vector3.TransformNormal(v.nrm, sb);
}

View File

@ -168,12 +168,15 @@ namespace FirstPlugin
private static void SetBoneUniforms(ShaderProgram shader, CMDLWrapper fmdl, SOBJWrapper fshp)
{
for (int i = 0; i < fmdl.Skeleton.Renderable.bones.Count; i++)
foreach (var FaceGroup in fshp.Shape.FaceGroups)
{
GL.Uniform1(GL.GetUniformLocation(shader.program, String.Format("boneIds[{0}]", i)), i);
for (int i = 0; i < FaceGroup.BoneIndexList.Length; i++)
{
GL.Uniform1(GL.GetUniformLocation(shader.program, String.Format("boneIds[{0}]", i)), i);
Matrix4 transform = fmdl.Skeleton.Renderable.bones[i].invert * fmdl.Skeleton.Renderable.bones[i].Transform;
GL.UniformMatrix4(GL.GetUniformLocation(shader.program, String.Format("bones[{0}]", i)), false, ref transform);
Matrix4 transform = fmdl.Skeleton.Renderable.bones[(int)FaceGroup.BoneIndexList[i]].invert * fmdl.Skeleton.Renderable.bones[(int)FaceGroup.BoneIndexList[i]].Transform;
GL.UniformMatrix4(GL.GetUniformLocation(shader.program, String.Format("bones[{0}]", i)), false, ref transform);
}
}
}

View File

@ -23,6 +23,8 @@ out vec3 position;
out vec3 boneWeightsColored;
uniform int boneIds[190];
// Skinning uniforms
uniform mat4 bones[190];
@ -80,16 +82,16 @@ vec3 BoneWeightColor(float weights)
float BoneWeightDisplay(ivec4 index)
{
float weight = 0;
if (selectedBoneIndex == index.x)
if (selectedBoneIndex == boneIds[index.x])
weight += vWeight.x;
if (selectedBoneIndex == index.y)
if (selectedBoneIndex == boneIds[index.y])
weight += vWeight.y;
if (selectedBoneIndex == index.z)
if (selectedBoneIndex == boneIds[index.z])
weight += vWeight.z;
if (selectedBoneIndex == index.w)
if (selectedBoneIndex == boneIds[index.w])
weight += vWeight.w;
if (selectedBoneIndex == index.x && RigidSkinning == 1)
if (selectedBoneIndex == boneIds[index.x] && RigidSkinning == 1)
weight = 1;
if (selectedBoneIndex == SingleBoneIndex && NoSkinning == 1)
weight = 1;