#include "fsC3dAnimationData.h"
#include <algorithm>
#include <fsCore/fsStr.h>
#include <fsCore/src/debug/fsAssert.h>
#include <fsCore/src/fsCResourceName.h>
#include "fsC3dModelData.h"
fsStr fsC3dAnimationData::animationNameGet(const fsStr& pAnimationName) const<--- The member function 'fsC3dAnimationData::animationNameGet' can be static.
{
fsStr animName{pAnimationName};
return animName;
}
fsStr fsC3dAnimationData::filenameGet(const fsStr& pFileName, const fsStr& pAnimationName)
{
fsCResourceName resourceName(fsC3dModelData::modelFilenameGet(pFileName), fsCResourceName::eRES_LOCATION_ASSETS);
return resourceName.nameGet();
}
::ModelAnimation* const fsC3dAnimationData::get(const fsStr& panimationName)
{
const auto aniName = animationNameGet(panimationName);
auto anim = mAnims.find(aniName);
return anim != mAnims.end() ? anim->second : createRaylibAnimation(aniName);
}
::ModelAnimation* fsC3dAnimationData::createRaylibAnimation(const fsStr& pAnimationName)
{
fsStr downCaseFilename(fsCResourceName(fsC3dModelData::modelFilenameGet(mModelFilename), fsCResourceName::eRES_LOCATION_ASSETS).nameGet());
downCaseFilename.downcase();
auto animation = LoadModelAnimations(downCaseFilename.utf8Get(), &mAnimationCount);
mAnims.insert(std::pair<fsStr, ::ModelAnimation*>(pAnimationName, animation));
return animation;
}
fsC3dAnimationData::fsC3dAnimationData(const fsStr& pFileName, const fsStr& pAnimationName):
mAnimationCount(0),
mModelFilename(pFileName)
{
createRaylibAnimation(pAnimationName);
}
fsC3dAnimationData::~fsC3dAnimationData()
{
std::for_each(mAnims.begin(), mAnims.end(), [](std::pair<fsStr, ::ModelAnimation*> ani)
{
::UnloadModelAnimations(ani.second, 1);
});
}