|
5 | 5 | #include <vector> |
6 | 6 |
|
7 | 7 | #include "./Mesh.hpp" |
| 8 | +#include "./RaylibException.hpp" |
8 | 9 | #include "./raylib-cpp-utils.hpp" |
9 | 10 | #include "./raylib.hpp" |
10 | 11 |
|
@@ -43,6 +44,34 @@ class ModelAnimation : public ::ModelAnimation { |
43 | 44 | return mats; |
44 | 45 | } |
45 | 46 |
|
| 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 | + |
46 | 75 | GETTERSETTER(int, BoneCount, boneCount) |
47 | 76 | GETTERSETTER(int, KeyframeCount, keyframeCount) |
48 | 77 | GETTERSETTER(::Transform**, KeyframePoses, keyframePoses) |
|
0 commit comments