diff --git a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp index 6ef2d47e..26f6b83e 100644 --- a/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp +++ b/SHADE_Engine/src/Animation/SHAnimatorComponent.cpp @@ -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 diff --git a/SHADE_Engine/src/Animation/SHRig.cpp b/SHADE_Engine/src/Animation/SHRig.cpp index 6f9b2b85..84117f77 100644 --- a/SHADE_Engine/src/Animation/SHRig.cpp +++ b/SHADE_Engine/src/Animation/SHRig.cpp @@ -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()) diff --git a/SHADE_Engine/src/Animation/SHRig.h b/SHADE_Engine/src/Animation/SHRig.h index 3d2b14c2..f28c628b 100644 --- a/SHADE_Engine/src/Animation/SHRig.h +++ b/SHADE_Engine/src/Animation/SHRig.h @@ -80,6 +80,7 @@ namespace SHADE /// /// Handle to the root node of the rig. Handle GetRootNode() const noexcept { return rootNode; } + const SHMatrix& GetGlobalInverseMatrix() const noexcept { return globalInverseMatrix; } /// /// Retrieves a node via name. /// @@ -108,6 +109,7 @@ namespace SHADE std::unordered_map> nodesByName; std::vector> nodes; std::unordered_map, int> nodeIndexMap; + SHMatrix globalInverseMatrix; SHResourceLibrary nodeStore; /*---------------------------------------------------------------------------------*/