Added Global Inverse Matrix for SHRig

This commit is contained in:
Kah Wei 2023-01-18 20:11:48 +08:00
parent a543f6cc3a
commit 62f104a535
3 changed files with 8 additions and 2 deletions

View File

@ -166,7 +166,7 @@ namespace SHADE
const int BONE_MTX_IDX = rig->GetNodeIndex(node);
if (BONE_MTX_IDX >= 0)
{
boneMatrices[BONE_MTX_IDX] = boneMatrices[BONE_MTX_IDX] * transformMatrix * node->OffsetMatrix;
boneMatrices[BONE_MTX_IDX] = rig->GetGlobalInverseMatrix() * transformMatrix * node->OffsetMatrix;
}
// Apply pose to children

View File

@ -34,6 +34,10 @@ namespace SHADE
// Do a recursive depth first traversal to populate the rig
rootNode = recurseCreateNode(asset, asset.root);
if (rootNode)
{
globalInverseMatrix = rootNode->OffsetMatrix;
}
}
/*-----------------------------------------------------------------------------------*/
@ -82,7 +86,7 @@ namespace SHADE
// Fill the node with data
const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef);
newNode->OffsetMatrix = NODE_DATA.transform;
newNode->OffsetMatrix = SHMatrix::Inverse(NODE_DATA.transform);
// Populate maps
if (!NODE_DATA.name.empty())

View File

@ -80,6 +80,7 @@ namespace SHADE
/// </summary>
/// <returns>Handle to the root node of the rig.</returns>
Handle<SHRigNode> GetRootNode() const noexcept { return rootNode; }
const SHMatrix& GetGlobalInverseMatrix() const noexcept { return globalInverseMatrix; }
/// <summary>
/// Retrieves a node via name.
/// </summary>
@ -108,6 +109,7 @@ namespace SHADE
std::unordered_map<std::string, Handle<SHRigNode>> nodesByName;
std::vector<Handle<SHRigNode>> nodes;
std::unordered_map<Handle<SHRigNode>, int> nodeIndexMap;
SHMatrix globalInverseMatrix;
SHResourceLibrary<SHRigNode> nodeStore;
/*---------------------------------------------------------------------------------*/