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 <string>
5#include <vector>
6#include <string>
7#include <string_view>
8
9#include "./Mesh.hpp"
10#include "./raylib-cpp-utils.hpp"
11#include "./raylib.hpp"
12
13namespace raylib {
17class ModelAnimation : public ::ModelAnimation {
18public:
19 ModelAnimation(const ::ModelAnimation& model) { set(model); }
20
21 ModelAnimation(const ModelAnimation&) = delete;
22
23 ModelAnimation(ModelAnimation&& other) noexcept {
24 set(other);
25
26 other.boneCount = 0;
27 other.frameCount = 0;
28 other.bones = nullptr;
29 other.framePoses = nullptr;
30 }
31
32 ~ModelAnimation() { Unload(); }
33
37 static std::vector<ModelAnimation> Load(const std::string_view fileName) {
38 int count = 0;
39 ::ModelAnimation* modelAnimations = ::LoadModelAnimations(fileName.data(), &count);
40 std::vector<ModelAnimation> mats(modelAnimations, modelAnimations + count);
41
42 RL_FREE(modelAnimations);
43
44 return mats;
45 }
46
47 GETTERSETTER(int, BoneCount, boneCount)
48 GETTERSETTER(::BoneInfo*, Bones, bones)
49 GETTERSETTER(int, FrameCount, frameCount)
50 GETTERSETTER(::Transform**, FramePoses, framePoses)
51
52 ModelAnimation& operator=(const ::ModelAnimation& model) {
53 set(model);
54 return *this;
55 }
56
57 ModelAnimation& operator=(const ModelAnimation&) = delete;
58
59 ModelAnimation& operator=(ModelAnimation&& other) noexcept {
60 if (this == &other) {
61 return *this;
62 }
63
64 Unload();
65 set(other);
66
67 other.boneCount = 0;
68 other.frameCount = 0;
69 other.bones = nullptr;
70 other.framePoses = nullptr;
71
72 return *this;
73 }
74
78 void Unload() { ::UnloadModelAnimation(*this); }
79
83 ModelAnimation& Update(const ::Model& model, int frame) {
84 ::UpdateModelAnimation(model, *this, frame);
85 return *this;
86 }
87
91 ModelAnimation& UpdateBones(const ::Model& model, int frame) {
92 ::UpdateModelAnimationBones(model, *this, frame);
93 return *this;
94 }
95
99 [[nodiscard]] bool IsValid(const ::Model& model) const { return ::IsModelAnimationValid(model, *this); }
100protected:
101 void set(const ::ModelAnimation& model) {
102 boneCount = model.boneCount;
103 frameCount = model.frameCount;
104 bones = model.bones;
105 framePoses = model.framePoses;
106
107 // Duplicate the name. TextCopy() uses the null terminator, which we ignore here.
108 for (int i = 0; i < 32; i++) {
109 name[i] = model.name[i];
110 }
111 }
112};
113} // namespace raylib
114
116
117#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 & UpdateBones(const ::Model &model, int frame)
Update model animation mesh bone matrices (GPU skinning)
ModelAnimation & Update(const ::Model &model, int frame)
Update model animation pose.
void Unload()
Unload animation data.
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8