raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
ModelAnimation.hpp
1#ifndef RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
2#define RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
3
4#include <vector>
5#include <string>
6#include <string_view>
7
8#include "./raylib.hpp"
9#include "./raylib-cpp-utils.hpp"
10#include "./Mesh.hpp"
11
12namespace raylib {
16class ModelAnimation : public ::ModelAnimation {
17 public:
18 ModelAnimation(const ::ModelAnimation& model) {
19 set(model);
20 }
21
22 ModelAnimation(const ModelAnimation&) = delete;
23
25 set(other);
26
27 other.boneCount = 0;
28 other.frameCount = 0;
29 other.bones = nullptr;
30 other.framePoses = nullptr;
31 }
32
34 Unload();
35 }
36
40 static std::vector<ModelAnimation> Load(const std::string_view fileName) {
41 int count = 0;
42 ::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.data(), &count);
43 std::vector<ModelAnimation> mats(modelAnimations, modelAnimations + count);
44
45 RL_FREE(modelAnimations);
46
47 return mats;
48 }
49
50 GETTERSETTER(int, BoneCount, boneCount)
51 GETTERSETTER(::BoneInfo*, Bones, bones)
52 GETTERSETTER(int, FrameCount, frameCount)
53 GETTERSETTER(::Transform**, FramePoses, framePoses)
54
55 ModelAnimation& operator=(const ::ModelAnimation& model) {
56 set(model);
57 return *this;
58 }
59
60 ModelAnimation& operator=(const ModelAnimation&) = delete;
61
62 ModelAnimation& operator=(ModelAnimation&& other) noexcept {
63 if (this == &other) {
64 return *this;
65 }
66
67 Unload();
68 set(other);
69
70 other.boneCount = 0;
71 other.frameCount = 0;
72 other.bones = nullptr;
73 other.framePoses = nullptr;
74
75 return *this;
76 }
77
81 void Unload() {
82 ::UnloadModelAnimation(*this);
83 }
84
88 ModelAnimation& Update(const ::Model& model, int frame) {
89 ::UpdateModelAnimation(model, *this, frame);
90 return *this;
91 }
92
96 bool IsValid(const ::Model& model) const {
97 return ::IsModelAnimationValid(model, *this);
98 }
99
100 protected:
101 void set(const ::ModelAnimation& model) {
102 boneCount = model.boneCount;
103 frameCount = model.frameCount;
104 bones = model.bones;
105 framePoses = model.framePoses;
106 }
107};
108} // namespace raylib
109
111
112#endif // RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
Matrix type (OpenGL style 4x4 - right handed, column major)
Definition: Matrix.hpp:18
static std::vector< ModelAnimation > Load(const std::string_view fileName)
Load model animations from file.
bool IsValid(const ::Model &model) const
Check model animation skeleton match.
ModelAnimation & Update(const ::Model &model, int frame)
Update model animation pose.
void Unload()
Unload animation data.