Fix model importer to use precomputed Offset Matrix for skeletal model bones

#1525
This commit is contained in:
Wojtek Figat
2023-10-03 22:30:58 +02:00
parent 4e83a0a757
commit 68a713fb95
3 changed files with 21 additions and 65 deletions

View File

@@ -1320,14 +1320,17 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
}
}
// Apply import transform on root bones
for (int32 i = 0; i < data.Skeleton.Bones.Count(); i++)
// Apply import transform on bones
Matrix importMatrixInv;
importTransform.GetWorld(importMatrixInv);
importMatrixInv.Invert();
for (SkeletonBone& bone : data.Skeleton.Bones)
{
auto& bone = data.Skeleton.Bones.Get()[i];
if (bone.ParentIndex == -1)
{
bone.LocalTransform = importTransform.LocalToWorld(bone.LocalTransform);
}
bone.OffsetMatrix = importMatrixInv * bone.OffsetMatrix;
}
}
@@ -1363,20 +1366,21 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
// use SkeletonMapping<SkeletonBone> to map bones?
// Calculate offset matrix (inverse bind pose transform) for every bone manually
{
for (int32 i = 0; i < data.Skeleton.Bones.Count(); i++)
/*{
for (SkeletonBone& bone : data.Skeleton.Bones)
{
Matrix t = Matrix::Identity;
int32 idx = data.Skeleton.Bones[i].NodeIndex;
int32 idx = bone.NodeIndex;
do
{
t *= data.Skeleton.Nodes[idx].LocalTransform.GetWorld();
idx = data.Skeleton.Nodes[idx].ParentIndex;
const SkeletonNode& node = data.Skeleton.Nodes[idx];
t *= node.LocalTransform.GetWorld();
idx = node.ParentIndex;
} while (idx != -1);
t.Invert();
data.Skeleton.Bones[i].OffsetMatrix = t;
bone.OffsetMatrix = t;
}
}
}*/
#if USE_SKELETON_NODES_SORTING
// Sort skeleton nodes and bones hierarchy (parents first)