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

View File

@ -86,7 +86,8 @@ namespace SHADE
// Fill the node with data
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
if (!NODE_DATA.name.empty())

View File

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