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
7 changed files with 52 additions and 20 deletions
Showing only changes of commit da8c759288 - Show all commits

View File

@ -71,7 +71,7 @@ namespace SHADE
Play(); Play();
// Set to initial pose // Set to initial pose
if (rig && rig->GetRootNode()) if (rig && !rig->GetRootNodes().empty())
{ {
updateCurrentAnimatorState(currClip, 0.0f); updateCurrentAnimatorState(currClip, 0.0f);
} }
@ -124,7 +124,7 @@ namespace SHADE
std::fill(boneMatrices.begin(), boneMatrices.end(), SHMatrix::Identity); std::fill(boneMatrices.begin(), boneMatrices.end(), SHMatrix::Identity);
// Do not do anything if is not playing or there's nothing to animate // Do not do anything if is not playing or there's nothing to animate
if (!rig || !rig->GetRootNode()) if (!rig || rig->GetRootNodes().empty())
return; return;
// We want to still display a paused pose, so we only prevent progression // 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) void SHAnimatorComponent::updateCurrentAnimatorState(Handle<SHAnimationClip> clip, float playbackTime)
{ {
// Nothing to animate // Nothing to animate
if (!clip || !rig || !rig->GetRootNode()) if (!clip || !rig || rig->GetRootNodes().empty())
return; return;
// Check that we have animation data // Check that we have animation data
@ -286,7 +286,10 @@ namespace SHADE
} }
void SHAnimatorComponent::updatePoseWithClip(Handle<SHAnimationClip> clip, float poseTime) 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) 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 // 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) if (rootNode)
{ {
globalInverseMatrix = SHMatrix::Inverse(rootNode->TransformMatrix); rootNodes.emplace_back(rootNode);
} }
} }
SHRig::SHRig(SHRig&& rhs) SHRig::SHRig(SHRig&& rhs)
: rootNode { rhs.rootNode } : rootNodes { std::move(rhs.rootNodes) }
, nodeNames { std::move(rhs.nodeNames) } , nodeNames { std::move(rhs.nodeNames) }
, nodesByName { std::move(rhs.nodesByName) } , nodesByName { std::move(rhs.nodesByName) }
, nodes { std::move(rhs.nodes) } , nodes { std::move(rhs.nodes) }
, nodeIndexMap { std::move(rhs.nodeIndexMap) } , nodeIndexMap { std::move(rhs.nodeIndexMap) }
, globalInverseMatrix { std::move(rhs.globalInverseMatrix) }
{ {
rhs.rootNode = {}; rhs.nodes = {};
} }
SHRig::~SHRig() SHRig::~SHRig()
{ {
@ -63,17 +62,17 @@ namespace SHADE
SHRig& SHRig::operator=(SHRig&& rhs) SHRig& SHRig::operator=(SHRig&& rhs)
{ {
rootNode = rhs.rootNode; rootNodes = std::move(rhs.rootNodes);
nodeNames = std::move(rhs.nodeNames); nodeNames = std::move(rhs.nodeNames);
nodesByName = std::move(rhs.nodesByName); nodesByName = std::move(rhs.nodesByName);
nodes = std::move(rhs.nodes); nodes = std::move(rhs.nodes);
nodeIndexMap = std::move(rhs.nodeIndexMap); nodeIndexMap = std::move(rhs.nodeIndexMap);
globalInverseMatrix = std::move(rhs.globalInverseMatrix);
rhs.rootNode = {}; rhs.rootNodes = {};
return *this; return *this;
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Usage Functions */ /* Usage Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

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

View File

@ -822,6 +822,16 @@ namespace SHADE
instance->setVolume(volume); instance->setVolume(volume);
} }
bool AudioClip::GetDestroyOnSceneExit()
{
return destroyOnSceneExit;
}
void AudioClip::SetDestroyOnSceneExit(bool value)
{
destroyOnSceneExit = value;
}
SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent) SHEventHandle SHAudioSystem::onStop(SHEventPtr onStopEvent)
{ {
StopAllSounds(); StopAllSounds();
@ -840,10 +850,13 @@ namespace SHADE
{ {
auto [begin, end] = audioClipLibrary.GetDenseAccess(); auto [begin, end] = audioClipLibrary.GetDenseAccess();
for (auto& it = begin; it != end; ++it) for (auto& it = begin; it != end; ++it)
{
if(it->destroyOnSceneExit)
{ {
it->instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT); it->instance->stop(FMOD_STUDIO_STOP_ALLOWFADEOUT);
it->instance->release(); it->instance->release();
} }
}
return onSceneExitEvent->handle; return onSceneExitEvent->handle;
} }

View File

@ -37,10 +37,13 @@ namespace SHADE
float GetParameterValue(const char* paramName); float GetParameterValue(const char* paramName);
float GetVolume(); float GetVolume();
void SetVolume(float volume); void SetVolume(float volume);
bool GetDestroyOnSceneExit();
void SetDestroyOnSceneExit(bool value);
friend class SHAudioSystem; friend class SHAudioSystem;
private: private:
FMOD::Studio::EventInstance* instance = nullptr; FMOD::Studio::EventInstance* instance = nullptr;
EntityID transformRef = MAX_EID; EntityID transformRef = MAX_EID;
bool destroyOnSceneExit = true;
}; };
class SH_API SHAudioSystem : public SHSystem class SH_API SHAudioSystem : public SHSystem

View File

@ -44,6 +44,16 @@ namespace SHADE
return SHResourceManagerInterface::GetAssetID(Convert::ToNative(audioClipInstHandle)).value_or(INVALID_ASSET_ID); return SHResourceManagerInterface::GetAssetID(Convert::ToNative(audioClipInstHandle)).value_or(INVALID_ASSET_ID);
} }
bool AudioClipHandler::DestroyOnSceneExit::get()
{
return NativeObject->GetDestroyOnSceneExit();
}
void AudioClipHandler::DestroyOnSceneExit::set(bool value)
{
NativeObject->SetDestroyOnSceneExit(value);
}
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Constructors/Destructor */ /* Constructors/Destructor */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -54,6 +54,12 @@ namespace SHADE
AssetID get(); AssetID get();
} }
property bool DestroyOnSceneExit
{
bool get();
void set(bool value);
}
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Constructors/Destructor */ /* Constructors/Destructor */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/