SHAnimatorComponent and SHRig now use the proper transform and offset matrices

This commit is contained in:
Kah Wei 2023-01-22 21:43:37 +08:00
parent 80fb8f7c73
commit 354d9434f6
3 changed files with 9 additions and 8 deletions

View File

@ -143,7 +143,7 @@ namespace SHADE
{ {
// Check if there is a channel for this node // Check if there is a channel for this node
const std::string& BONE_NAME = rig->GetName(node); const std::string& BONE_NAME = rig->GetName(node);
SHMatrix transformMatrix = SHMatrix::Identity; SHMatrix transformMatrix = node->TransformMatrix;
if (channelMap.contains(BONE_NAME)) if (channelMap.contains(BONE_NAME))
{ {
const auto CHANNEL = channelMap[BONE_NAME]; const auto CHANNEL = channelMap[BONE_NAME];
@ -154,19 +154,15 @@ namespace SHADE
getInterpolatedValue(CHANNEL->ScaleKeyFrames, closestFrameIndex, poseTime) getInterpolatedValue(CHANNEL->ScaleKeyFrames, closestFrameIndex, poseTime)
); );
} }
else
{
transformMatrix = SHMatrix::Inverse(node->OffsetMatrix); // TODO: Use TransformMatrix for the bone
}
// Apply parent's transformation // Apply parent's transformation
transformMatrix = parentMatrix * transformMatrix; transformMatrix = transformMatrix * parentMatrix;
// Apply transformations to this node // Apply transformations to this node
const int BONE_MTX_IDX = rig->GetNodeIndex(node); const int BONE_MTX_IDX = rig->GetNodeIndex(node);
if (BONE_MTX_IDX >= 0) if (BONE_MTX_IDX >= 0)
{ {
boneMatrices[BONE_MTX_IDX] = rig->GetGlobalInverseMatrix() * transformMatrix * node->OffsetMatrix; boneMatrices[BONE_MTX_IDX] = node->OffsetMatrix * transformMatrix * rig->GetGlobalInverseMatrix();
} }
// Apply pose to children // Apply pose to children

View File

@ -86,7 +86,8 @@ namespace SHADE
// Fill the node with data // Fill the node with data
const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef); const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef);
newNode->OffsetMatrix = SHMatrix::Inverse(NODE_DATA.transform); newNode->OffsetMatrix = SHMatrix::Transpose(NODE_DATA.offset);
newNode->TransformMatrix = SHMatrix::Transpose(NODE_DATA.transform);
// Populate maps // Populate maps
if (!NODE_DATA.name.empty()) if (!NODE_DATA.name.empty())

View File

@ -43,6 +43,10 @@ namespace SHADE
/// </summary> /// </summary>
SHMatrix OffsetMatrix; SHMatrix OffsetMatrix;
/// <summary> /// <summary>
/// Matrix that performs a transformation from bone (node) space to local space.
/// </summary>
SHMatrix TransformMatrix;
/// <summary>
/// Child nodes of this node. /// Child nodes of this node.
/// </summary> /// </summary>
std::vector<Handle<SHRigNode>> Children; std::vector<Handle<SHRigNode>> Children;