Add CalculateBoneOffsetMatrices option to fix some animated model skeletons rendering

#1862
This commit is contained in:
Wojtek Figat
2023-11-04 20:32:52 +01:00
parent a7bb236344
commit c5d3954bc8
2 changed files with 14 additions and 9 deletions

View File

@@ -367,6 +367,7 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj
SERIALIZE(ImportLODs);
SERIALIZE(ImportVertexColors);
SERIALIZE(ImportBlendShapes);
SERIALIZE(CalculateBoneOffsetMatrices);
SERIALIZE(LightmapUVsSource);
SERIALIZE(CollisionMeshesPrefix);
SERIALIZE(Scale);
@@ -413,6 +414,7 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi
DESERIALIZE(ImportLODs);
DESERIALIZE(ImportVertexColors);
DESERIALIZE(ImportBlendShapes);
DESERIALIZE(CalculateBoneOffsetMatrices);
DESERIALIZE(LightmapUVsSource);
DESERIALIZE(CollisionMeshesPrefix);
DESERIALIZE(Scale);
@@ -1418,6 +1420,15 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
SkeletonUpdater<ImportedModelData::Node> hierarchyUpdater(data.Nodes);
hierarchyUpdater.UpdateMatrices();
if (options.CalculateBoneOffsetMatrices)
{
// Calculate offset matrix (inverse bind pose transform) for every bone manually
for (SkeletonBone& bone : data.Skeleton.Bones)
{
CalculateBoneOffsetMatrix(data.Skeleton.Nodes, bone.OffsetMatrix, bone.NodeIndex);
}
}
// Move meshes in the new nodes
for (int32 lodIndex = 0; lodIndex < data.LODs.Count(); lodIndex++)
{
@@ -1439,15 +1450,6 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
}
}
// TODO: allow to link skeleton asset to model to retarget model bones skeleton for an animation
// use SkeletonMapping<SkeletonBone> to map bones?
// Calculate offset matrix (inverse bind pose transform) for every bone manually
/*for (SkeletonBone& bone : data.Skeleton.Bones)
{
CalculateBoneOffsetMatrix(data.Skeleton.Nodes, bone.OffsetMatrix, bone.NodeIndex);
}*/
#if USE_SKELETON_NODES_SORTING
// Sort skeleton nodes and bones hierarchy (parents first)
// Then it can be used with a simple linear loop update