forked from RobLoach/raylib-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelAnimation.hpp
More file actions
112 lines (88 loc) · 2.94 KB
/
ModelAnimation.hpp
File metadata and controls
112 lines (88 loc) · 2.94 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
#define RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_
#include <string>
#include <vector>
#include "./Mesh.hpp"
#include "./raylib-cpp-utils.hpp"
#include "./raylib.hpp"
namespace raylib {
/**
* Model animation
*/
class ModelAnimation : public ::ModelAnimation {
public:
ModelAnimation(const ::ModelAnimation& model) { set(model); }
ModelAnimation(const ModelAnimation&) = delete;
ModelAnimation(ModelAnimation&& other) noexcept {
set(other);
other.boneCount = 0;
other.keyframeCount = 0;
other.keyframePoses = nullptr;
}
// TODO: Implement a way to unload all animations at once, as the current Unload() only unloads one animation.
~ModelAnimation() { Unload(1); }
/**
* Load model animations from file
*/
static std::vector<ModelAnimation> Load(const std::string& fileName) {
int count = 0;
::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.c_str(), &count);
std::vector<ModelAnimation> mats(modelAnimations, modelAnimations + count);
RL_FREE(modelAnimations);
return mats;
}
GETTERSETTER(int, BoneCount, boneCount)
GETTERSETTER(int, KeyframeCount, keyframeCount)
GETTERSETTER(::Transform**, KeyframePoses, keyframePoses)
ModelAnimation& operator=(const ::ModelAnimation& model) {
set(model);
return *this;
}
ModelAnimation& operator=(const ModelAnimation&) = delete;
ModelAnimation& operator=(ModelAnimation&& other) noexcept {
if (this == &other) {
return *this;
}
Unload(1);
set(other);
other.boneCount = 0;
other.keyframeCount = 0;
other.keyframePoses = nullptr;
return *this;
}
/**
* Unload animation data
*/
void Unload(int animCount) { ::UnloadModelAnimations(this, animCount); }
/**
* Update model animation pose
*/
ModelAnimation& Update(const ::Model& model, int frame) {
::UpdateModelAnimation(model, *this, frame);
return *this;
}
/**
* Update model animation mesh bone matrices (GPU skinning)
*/
ModelAnimation& UpdateBones(const ::Model& model, int frame) {
::UpdateModelAnimation(model, *this, frame);
return *this;
}
/**
* Check model animation skeleton match
*/
[[nodiscard]] bool IsValid(const ::Model& model) const { return ::IsModelAnimationValid(model, *this); }
protected:
void set(const ::ModelAnimation& model) {
boneCount = model.boneCount;
keyframeCount = model.keyframeCount;
keyframePoses = model.keyframePoses;
// Duplicate the name. TextCopy() uses the null terminator, which we ignore here.
for (int i = 0; i < 32; i++) {
name[i] = model.name[i];
}
}
};
} // namespace raylib
using RModelAnimation = raylib::ModelAnimation;
#endif // RAYLIB_CPP_INCLUDE_MODELANIMATION_HPP_