1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#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);
	});
}