1
0
mirror of synced 2025-02-21 04:58:41 +01:00

BFRES : Cleanup how indices are checked and updated fixing some skinning bugs on import.

This commit is contained in:
KillzXGaming 2021-04-26 20:35:44 -04:00
parent 7c9d8cfd98
commit f1da5060d0
4 changed files with 7 additions and 112 deletions

View File

@ -1110,7 +1110,6 @@ namespace Bfres.Structs
}
}
//Genericate indices
//Check for rigged bones
for (int ob = 0; ob < ImportedObjects.Count; ob++)
@ -1125,8 +1124,6 @@ namespace Bfres.Structs
}
}
Skeleton.CalculateIndices();
List<int> smoothSkinningIndices = new List<int>();
List<int> rigidSkinningIndices = new List<int>();
@ -1215,7 +1212,6 @@ namespace Bfres.Structs
}
}
if (Skeleton.node.SkeletonU != null)
{
Skeleton.node.SkeletonU.MatrixToBoneList = new List<ushort>();
@ -1229,6 +1225,8 @@ namespace Bfres.Structs
Skeleton.node.Skeleton.MatrixToBoneList.Add((ushort)skinningIndices[i]);
}
Skeleton.CalculateIndices();
if (materials.Count <= 0)
{
//Force material creation if there is none present

View File

@ -28,20 +28,13 @@ namespace Bfres.Structs
if (Skeleton.InverseModelMatrices == null)
Skeleton.InverseModelMatrices = new List<Syroot.Maths.Matrix3x4>();
if (Skeleton.MatrixToBoneList == null)
Skeleton.MatrixToBoneList = new List<ushort>();
//Generate index list
List<ushort> SmoothIndices = new List<ushort>();
List<Syroot.Maths.Matrix3x4> SmoothMatrices = new List<Syroot.Maths.Matrix3x4>();
List<ushort> RigidIndices = new List<ushort>();
foreach (var Bone in Skeleton.Bones.Values)
Bone.InverseMatrix = new Syroot.Maths.Matrix3x4(1,0,0,0,
0,1,0,0,
0,0,1,0);
ushort SmoothIndex = 0;
foreach (BfresBone bn in bones)
{
ushort BoneIndex = 0;
@ -49,13 +42,8 @@ namespace Bfres.Structs
{
if (bn.Text == Bone.Name)
{
if (bn.UseSmoothMatrix || bn.SmoothMatrixIndex > -1)
if (bn.UseSmoothMatrix)
{
bn.SmoothMatrixIndex = (short)SmoothIndex++;
Bone.SmoothMatrixIndex = bn.SmoothMatrixIndex;
SmoothIndices.Add(BoneIndex);
var mat = MatrixExenstion.GetMatrixInverted(bn);
Bone.InverseMatrix = mat;
SmoothMatrices.Add(mat);
@ -64,30 +52,7 @@ namespace Bfres.Structs
BoneIndex++;
}
}
//Rigid Indices come after smooth indices. Start from the last smooth index
ushort RigidIndex = (ushort)(SmoothIndices.Count);
foreach (BfresBone bn in bones)
{
ushort BoneIndex = 0;
foreach (var Bone in Skeleton.Bones.Values)
{
if (bn.Text == Bone.Name)
{
if (bn.UseRigidMatrix || bn.RigidMatrixIndex != -1)
{
bn.RigidMatrixIndex = (short)RigidIndex++;
Bone.RigidMatrixIndex = bn.RigidMatrixIndex;
RigidIndices.Add(BoneIndex);
}
}
BoneIndex++;
}
}
//Rigid indices at the end
var AllIndices = SmoothIndices.Concat(RigidIndices).ToList();
Skeleton.MatrixToBoneList = AllIndices.ToArray();
Skeleton.InverseModelMatrices = SmoothMatrices;
}
else
@ -96,16 +61,8 @@ namespace Bfres.Structs
if (Skeleton.InverseModelMatrices == null)
Skeleton.InverseModelMatrices = new List<Syroot.Maths.Matrix3x4>();
if (Skeleton.MatrixToBoneList == null)
Skeleton.MatrixToBoneList = new List<ushort>();
//Generate index list
List<ushort> SmoothIndices = new List<ushort>();
List<Syroot.Maths.Matrix3x4> SmoothMatrices = new List<Syroot.Maths.Matrix3x4>();
List<ushort> RigidIndices = new List<ushort>();
ushort SmoothIndex = 0;
foreach (BfresBone bn in bones)
{
ushort BoneIndex = 0;
@ -115,10 +72,6 @@ namespace Bfres.Structs
{
if (bn.UseSmoothMatrix || bn.SmoothMatrixIndex != -1)
{
bn.SmoothMatrixIndex = (short)SmoothIndex++;
Bone.SmoothMatrixIndex = bn.SmoothMatrixIndex;
SmoothIndices.Add(BoneIndex);
var mat = MatrixExenstion.GetMatrixInverted(bn);
SmoothMatrices.Add(mat);
}
@ -126,31 +79,6 @@ namespace Bfres.Structs
BoneIndex++;
}
}
//Rigid Indices come after smooth indices. Start from the last smooth index
ushort RigidIndex = (ushort)(SmoothIndices.Count);
foreach (BfresBone bn in bones)
{
ushort BoneIndex = 0;
foreach (var Bone in Skeleton.Bones)
{
if (bn.Text == Bone.Name)
{
if (bn.UseRigidMatrix || bn.RigidMatrixIndex != -1)
{
bn.RigidMatrixIndex = (short)RigidIndex++;
Bone.RigidMatrixIndex = bn.RigidMatrixIndex;
RigidIndices.Add(BoneIndex);
}
}
BoneIndex++;
}
}
//Rigid indices at the end
var AllIndices = SmoothIndices.Concat(RigidIndices).ToList();
Skeleton.MatrixToBoneList = AllIndices.ToArray();
Skeleton.InverseModelMatrices = SmoothMatrices;
}
}
@ -615,9 +543,9 @@ namespace Bfres.Structs
}
public class BfresBone : STBone, IContextMenuNode
{
public bool UseSmoothMatrix { get; set; }
public bool UseSmoothMatrix => SmoothMatrixIndex != -1;
public bool UseRigidMatrix { get; set; }
public bool UseRigidMatrix => RigidMatrixIndex != -1;
public string BoneName
{

View File

@ -567,8 +567,6 @@ namespace FirstPlugin
bone.Text = bn.Name;
bone.RigidMatrixIndex = bn.RigidMatrixIndex;
bone.SmoothMatrixIndex = bn.SmoothMatrixIndex;
bone.UseRigidMatrix = bn.RigidMatrixIndex != -1;
bone.UseSmoothMatrix = bn.SmoothMatrixIndex != -1;
bone.BillboardIndex = bn.BillboardIndex;
if (SetParent)
@ -597,7 +595,6 @@ namespace FirstPlugin
public static void SaveSkeleton(FSKL fskl, List<STBone> Bones)
{
fskl.node.Skeleton.Bones.Clear();
fskl.node.Skeleton.MatrixToBoneList = new List<ushort>();
fskl.node.Skeleton.InverseModelMatrices = new List<Syroot.Maths.Matrix3x4>();
ushort SmoothIndex = 0;
@ -609,17 +606,11 @@ namespace FirstPlugin
BfresBone bn = new BfresBone(fskl);
bn.CloneBaseInstance(genericBone);
bn.Text = genericBone.Text;
bn.UseRigidMatrix = bn.RigidMatrixIndex != -1;
bn.UseSmoothMatrix = bn.SmoothMatrixIndex != -1;
//Set the bfres bone data
if (bn.Bone == null)
bn.Bone = new Bone();
bn.GenericToBfresBone();
if (bn.SmoothMatrixIndex != short.MaxValue)
fskl.node.Skeleton.MatrixToBoneList.Add(SmoothIndex++);
fskl.node.Skeleton.InverseModelMatrices.Add(Syroot.Maths.Matrix3x4.Zero);
//Check duplicated names
@ -639,14 +630,6 @@ namespace FirstPlugin
fskl.update();
fskl.reset();
fskl.Node_Array = new int[fskl.node.Skeleton.MatrixToBoneList.Count];
int nodes = 0;
foreach (ushort node in fskl.node.Skeleton.MatrixToBoneList)
{
fskl.Node_Array[nodes] = node;
nodes++;
}
}
public static void SetShape(this FSHP s, Shape shp)

View File

@ -381,8 +381,6 @@ namespace FirstPlugin
bone.RigidMatrixIndex = bn.RigidMatrixIndex;
bone.SmoothMatrixIndex = bn.SmoothMatrixIndex;
bone.BillboardIndex = bn.BillboardIndex;
bone.UseRigidMatrix = bn.RigidMatrixIndex != -1;
bone.UseSmoothMatrix = bn.SmoothMatrixIndex != -1;
if (SetParent)
bone.parentIndex = bn.ParentIndex;
if (bn.FlagsRotation == BoneFlagsRotation.Quaternion)
@ -954,7 +952,6 @@ namespace FirstPlugin
fskl.node.SkeletonU = new Skeleton();
fskl.node.SkeletonU.Bones.Clear();
fskl.node.SkeletonU.MatrixToBoneList = new List<ushort>();
fskl.node.SkeletonU.InverseModelMatrices = new List<Syroot.Maths.Matrix3x4>();
fskl.node.Nodes.Clear();
@ -973,9 +970,6 @@ namespace FirstPlugin
bn.BoneU = new Bone();
bn.GenericToBfresBone();
if (bn.SmoothMatrixIndex != short.MaxValue)
fskl.node.SkeletonU.MatrixToBoneList.Add(SmoothIndex++);
//Check duplicated names
List<string> names = fskl.bones.Select(o => o.Text).ToList();
bn.Text = Utils.RenameDuplicateString(names, bn.Text);
@ -996,14 +990,6 @@ namespace FirstPlugin
fskl.update();
fskl.reset();
fskl.Node_Array = new int[fskl.node.SkeletonU.MatrixToBoneList.Count];
int nodes = 0;
foreach (ushort node in fskl.node.SkeletonU.MatrixToBoneList)
{
fskl.Node_Array[nodes] = node;
nodes++;
}
}
public static void SaveVertexBuffer(FSHP fshp)
{