Enhanced functionality of animation clip container creation #432

Merged
XiaoQiDigipen merged 6 commits from SP3-13-Assets-Manager into main 2023-03-21 14:31:16 +08:00
3 changed files with 18 additions and 18 deletions
Showing only changes of commit 1476632220 - Show all commits

View File

@ -71,7 +71,7 @@ namespace SHADE
Play();
// Set to initial pose
if (rig && rig->GetRootNode())
if (rig && !rig->GetRootNodes().empty())
{
updateCurrentAnimatorState(currClip, 0.0f);
}
@ -124,7 +124,7 @@ namespace SHADE
std::fill(boneMatrices.begin(), boneMatrices.end(), SHMatrix::Identity);
// Do not do anything if is not playing or there's nothing to animate
if (!rig || !rig->GetRootNode())
if (!rig || rig->GetRootNodes().empty())
return;
// We want to still display a paused pose, so we only prevent progression
@ -274,7 +274,7 @@ namespace SHADE
void SHAnimatorComponent::updateCurrentAnimatorState(Handle<SHAnimationClip> clip, float playbackTime)
{
// Nothing to animate
if (!clip || !rig || !rig->GetRootNode())
if (!clip || !rig || rig->GetRootNodes().empty())
return;
// Check that we have animation data
@ -286,7 +286,10 @@ namespace SHADE
}
void SHAnimatorComponent::updatePoseWithClip(Handle<SHAnimationClip> clip, float poseTime)
{
updatePoseWithClip(poseTime, clip->GetRawAnimation(), rig->GetRootNode(), SHMatrix::Identity);
for (auto rootNode : rig->GetRootNodes())
{
updatePoseWithClip(poseTime, clip->GetRawAnimation(), rootNode, SHMatrix::Identity);
}
}
void SHAnimatorComponent::updatePoseWithClip(float poseTime, Handle<SHRawAnimation> rawAnimData, Handle<SHRigNode> node, const SHMatrix& parentMatrix)

View File

@ -33,22 +33,21 @@ namespace SHADE
}
// Do a recursive depth first traversal to populate the rig
rootNode = recurseCreateNode(asset, asset.root, nodeStore);
auto rootNode = recurseCreateNode(asset, asset.root, nodeStore);
if (rootNode)
{
globalInverseMatrix = SHMatrix::Inverse(rootNode->TransformMatrix);
rootNodes.emplace_back(rootNode);
}
}
SHRig::SHRig(SHRig&& rhs)
: rootNode { rhs.rootNode }
: rootNodes { std::move(rhs.rootNodes) }
, nodeNames { std::move(rhs.nodeNames) }
, nodesByName { std::move(rhs.nodesByName) }
, nodes { std::move(rhs.nodes) }
, nodeIndexMap { std::move(rhs.nodeIndexMap) }
, globalInverseMatrix { std::move(rhs.globalInverseMatrix) }
{
rhs.rootNode = {};
rhs.nodes = {};
}
SHRig::~SHRig()
{
@ -63,17 +62,17 @@ namespace SHADE
SHRig& SHRig::operator=(SHRig&& rhs)
{
rootNode = rhs.rootNode;
rootNodes = std::move(rhs.rootNodes);
nodeNames = std::move(rhs.nodeNames);
nodesByName = std::move(rhs.nodesByName);
nodes = std::move(rhs.nodes);
nodeIndexMap = std::move(rhs.nodeIndexMap);
globalInverseMatrix = std::move(rhs.globalInverseMatrix);
rhs.rootNode = {};
rhs.rootNodes = {};
return *this;
}
/*-----------------------------------------------------------------------------------*/
/* Usage Functions */
/*-----------------------------------------------------------------------------------*/

View File

@ -104,11 +104,10 @@ namespace SHADE
/// </returns>
const std::string& GetName(Handle<SHRigNode> node) const noexcept;
/// <summary>
/// Retrieves the root node of the rig.
/// Retrieves a read only reference to the root nodes of this rig.
/// </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; }
/// <returns>Vector of handles to the root node of the rig.</returns>
const std::vector<Handle<SHRigNode>>& GetRootNodes() const noexcept { return rootNodes; }
/// <summary>
/// Retrieves a node via name.
/// </summary>
@ -132,12 +131,11 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
/* Data Members */
/*---------------------------------------------------------------------------------*/
Handle<SHRigNode> rootNode;
std::vector<Handle<SHRigNode>> rootNodes;
std::unordered_map<Handle<SHRigNode>, std::string> nodeNames;
std::unordered_map<std::string, Handle<SHRigNode>> nodesByName;
std::vector<Handle<SHRigNode>> nodes;
std::unordered_map<Handle<SHRigNode>, int> nodeIndexMap;
SHMatrix globalInverseMatrix;
/*---------------------------------------------------------------------------------*/
/* Helper Functions */