Skip to content

Commit 79826ec

Browse files
authored
Add ModelAnimation::Load by index (#419)
1 parent 0171d33 commit 79826ec

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

include/ModelAnimation.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <vector>
66

77
#include "./Mesh.hpp"
8+
#include "./RaylibException.hpp"
89
#include "./raylib-cpp-utils.hpp"
910
#include "./raylib.hpp"
1011

@@ -43,6 +44,34 @@ class ModelAnimation : public ::ModelAnimation {
4344
return mats;
4445
}
4546

47+
/**
48+
* Load a single model animation from file by index
49+
*
50+
* @throws raylib::RaylibException Throws if the index is out of bounds.
51+
*/
52+
static ModelAnimation Load(const std::string& fileName, int index) {
53+
int count = 0;
54+
::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count);
55+
if (index < 0 || index >= count) {
56+
::UnloadModelAnimations(modelAnimations, count);
57+
throw RaylibException(TextFormat("ModelAnimation index %d out of range [0, %d)", index, count));
58+
}
59+
ModelAnimation result(modelAnimations[index]);
60+
modelAnimations[index].keyframePoses = nullptr;
61+
::UnloadModelAnimations(modelAnimations, count);
62+
return result;
63+
}
64+
65+
/**
66+
* Get the number of model animations in a file without fully loading them
67+
*/
68+
static int LoadCount(const std::string& fileName) {
69+
int count = 0;
70+
::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count);
71+
::UnloadModelAnimations(modelAnimations, count);
72+
return count;
73+
}
74+
4675
GETTERSETTER(int, BoneCount, boneCount)
4776
GETTERSETTER(int, KeyframeCount, keyframeCount)
4877
GETTERSETTER(::Transform**, KeyframePoses, keyframePoses)

0 commit comments

Comments
 (0)