BFRES : Fix rigid body transforming for model imports.

This commit is contained in:
KillzXGaming 2020-09-17 16:58:06 -04:00
parent b239823a3c
commit 6deffec924
2 changed files with 17 additions and 8 deletions

View file

@ -1219,7 +1219,13 @@ namespace Bfres.Structs
else else
shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount(); shape.VertexSkinCount = obj.GetMaxSkinInfluenceCount();
if (shape.VertexSkinCount == 1 && shape.BoneIndices.Count > 0) if (shape.VertexSkinCount == 0 && obj.boneList.Count > 0)
{
int boneIndex = Skeleton.bones.FindIndex(x => x.Text == obj.boneList[0]);
if (boneIndex != -1)
shape.BoneIndex = boneIndex;
}
else if (shape.VertexSkinCount == 1 && shape.BoneIndices.Count > 0)
{ {
int boneIndex = shape.BoneIndices[0]; int boneIndex = shape.BoneIndices[0];
shape.BoneIndex = boneIndex; shape.BoneIndex = boneIndex;

View file

@ -629,7 +629,7 @@ namespace Toolbox.Library
obj.HasUv1 = msh.HasTextureCoords(1); obj.HasUv1 = msh.HasTextureCoords(1);
obj.HasUv2 = msh.HasTextureCoords(2); obj.HasUv2 = msh.HasTextureCoords(2);
obj.HasIndices = msh.HasBones; obj.HasIndices = msh.HasBones;
if (msh.HasBones) if (msh.HasBones && msh.BoneCount > 1)
obj.HasWeights = msh.Bones[0].HasVertexWeights; obj.HasWeights = msh.Bones[0].HasVertexWeights;
obj.HasTans = msh.HasTangentBasis; obj.HasTans = msh.HasTangentBasis;
@ -679,8 +679,12 @@ namespace Toolbox.Library
List<string> bones = new List<string>(); List<string> bones = new List<string>();
foreach (Bone b in msh.Bones) foreach (Bone b in msh.Bones)
{ {
if (!bones.Contains(b.Name)) string name = b.Name;
bones.Add(b.Name); if (DaeHelper.IDMapToName.ContainsKey(name))
name = DaeHelper.IDMapToName[name];
if (!bones.Contains(name))
bones.Add(name);
} }
return bones; return bones;
} }
@ -723,8 +727,6 @@ namespace Toolbox.Library
{ {
Vertex vert = new Vertex(); Vertex vert = new Vertex();
Console.WriteLine($"{msh.Name} position {msh.Vertices[v]}");
if (msh.HasVertices) if (msh.HasVertices)
vert.pos = Vector3.TransformPosition(AssimpHelper.FromVector(msh.Vertices[v]), transform); vert.pos = Vector3.TransformPosition(AssimpHelper.FromVector(msh.Vertices[v]), transform);
if (msh.HasNormals) if (msh.HasNormals)
@ -744,8 +746,10 @@ namespace Toolbox.Library
if (msh.HasTangentBasis) if (msh.HasTangentBasis)
vert.bitan = new Vector4(msh.BiTangents[v].X, msh.BiTangents[v].Y, msh.BiTangents[v].Z, 1); vert.bitan = new Vector4(msh.BiTangents[v].X, msh.BiTangents[v].Y, msh.BiTangents[v].Z, 1);
vertices.Add(vert); vertices.Add(vert);
Console.WriteLine($"{msh.Name} COLOR { vert.col}");
} }
if (msh.HasBones) if (msh.HasBones && msh.BoneCount > 1)
{ {
for (int i = 0; i < msh.BoneCount; i++) for (int i = 0; i < msh.BoneCount; i++)
{ {
@ -767,7 +771,6 @@ namespace Toolbox.Library
} }
} }
return vertices; return vertices;
} }