raylib-cpp
C++ object-oriented wrapper library for raylib.
Model.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_MODEL_HPP_
2 #define RAYLIB_CPP_INCLUDE_MODEL_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 #include "./Mesh.hpp"
9 
10 namespace raylib {
14 class Model : public ::Model {
15  public:
16  Model(const ::Model& model) {
17  set(model);
18  }
19 
20  Model(const std::string& fileName) {
21  set(::LoadModel(fileName.c_str()));
22  }
23 
24  Model(const ::Mesh& mesh) {
25  set(::LoadModelFromMesh(mesh));
26  }
27 
28  ~Model() {
29  Unload();
30  }
31 
32  GETTERSETTER(::Matrix, Transform, transform)
33  GETTERSETTER(int, MeshCount, meshCount)
34  GETTERSETTER(int, MaterialCount, materialCount)
35  GETTERSETTER(::Mesh *, Meshes, meshes)
36  GETTERSETTER(::Material *, Materials, materials)
37  GETTERSETTER(int *, MeshMaterial, meshMaterial)
38  GETTERSETTER(int, BoneCount, boneCount)
39  GETTERSETTER(::BoneInfo *, Bones, bones)
40  GETTERSETTER(::Transform *, BindPoe, bindPose)
41 
42  Model& operator=(const ::Model& model) {
43  set(model);
44  return *this;
45  }
46 
50  inline void Unload() {
51  if (meshes != NULL || materials != NULL) {
52  ::UnloadModel(*this);
53  meshes = NULL;
54  materials = NULL;
55  }
56  }
57 
61  inline Model& UnloadKeepMeshes() {
62  ::UnloadModelKeepMeshes(*this);
63  return *this;
64  }
65 
69  inline Model& SetMeshMaterial(int meshId, int materialId) {
70  ::SetModelMeshMaterial(this, meshId, materialId);
71  return *this;
72  }
73 
77  inline RayHitInfo GetCollision(const ::Ray& ray) const {
78  return ::GetCollisionRayModel(ray, *this);
79  }
80 
84  inline Model& UpdateAnimation(const ::ModelAnimation& anim, int frame) {
85  ::UpdateModelAnimation(*this, anim, frame);
86  return *this;
87  }
88 
92  inline bool IsModelAnimationValid(const ::ModelAnimation& anim) const {
93  return ::IsModelAnimationValid(*this, anim);
94  }
95 
99  inline Model& Draw(::Vector3 position,
100  float scale = 1.0f,
101  ::Color tint = {255, 255, 255, 255}) {
102  ::DrawModel(*this, position, scale, tint);
103  return *this;
104  }
105 
109  inline Model& Draw(
110  ::Vector3 position,
111  ::Vector3 rotationAxis,
112  float rotationAngle = 0.0f,
113  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
114  ::Color tint = {255, 255, 255, 255}) {
115  ::DrawModelEx(*this, position, rotationAxis, rotationAngle, scale, tint);
116  return *this;
117  }
118 
122  inline Model& DrawWires(::Vector3 position,
123  float scale = 1.0f,
124  ::Color tint = {255, 255, 255, 255}) {
125  ::DrawModelWires(*this, position, scale, tint);
126  return *this;
127  }
128 
132  inline Model& DrawWires(
133  ::Vector3 position,
134  ::Vector3 rotationAxis,
135  float rotationAngle = 0.0f,
136  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
137  ::Color tint = {255, 255, 255, 255}) {
138  ::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint);
139  return *this;
140  }
141 
142  private:
143  inline void set(const ::Model& model) {
144  transform = model.transform;
145 
146  meshCount = model.meshCount;
147  materialCount = model.materialCount;
148  meshes = model.meshes;
149  materials = model.materials;
150  meshMaterial = model.meshMaterial;
151 
152  boneCount = model.boneCount;
153  bones = model.bones;
154  bindPose = model.bindPose;
155  }
156 };
157 } // namespace raylib
158 
159 #endif // RAYLIB_CPP_INCLUDE_MODEL_HPP_
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Matrix
Matrix type (OpenGL style 4x4 - right handed, column major)
Definition: Matrix.hpp:16
raylib::Model::DrawWires
Model & DrawWires(::Vector3 position, float scale=1.0f, ::Color tint={255, 255, 255, 255})
Draw a model wires (with texture if set)
Definition: Model.hpp:122
raylib::Model::DrawWires
Model & DrawWires(::Vector3 position, ::Vector3 rotationAxis, float rotationAngle=0.0f, ::Vector3 scale={1.0f, 1.0f, 1.0f}, ::Color tint={255, 255, 255, 255})
Draw a model wires (with texture if set) with extended parameters.
Definition: Model.hpp:132
raylib::Model::SetMeshMaterial
Model & SetMeshMaterial(int meshId, int materialId)
Set material for a mesh.
Definition: Model.hpp:69
raylib::Model::Draw
Model & Draw(::Vector3 position, float scale=1.0f, ::Color tint={255, 255, 255, 255})
Draw a model (with texture if set)
Definition: Model.hpp:99
raylib::Model::Draw
Model & Draw(::Vector3 position, ::Vector3 rotationAxis, float rotationAngle=0.0f, ::Vector3 scale={1.0f, 1.0f, 1.0f}, ::Color tint={255, 255, 255, 255})
Draw a model with extended parameters.
Definition: Model.hpp:109
raylib::Model::IsModelAnimationValid
bool IsModelAnimationValid(const ::ModelAnimation &anim) const
Check model animation skeleton match.
Definition: Model.hpp:92
raylib::Vector3
Vector3 type.
Definition: Vector3.hpp:16
raylib::Model::UpdateAnimation
Model & UpdateAnimation(const ::ModelAnimation &anim, int frame)
Update model animation pose.
Definition: Model.hpp:84
raylib::Mesh
Vertex data definning a mesh.
Definition: Mesh.hpp:16
raylib::Color
Color type, RGBA (32bit)
Definition: Color.hpp:14
raylib::Model
Model type.
Definition: Model.hpp:14
raylib::Model::GetCollision
RayHitInfo GetCollision(const ::Ray &ray) const
Get collision info between ray and model.
Definition: Model.hpp:77
raylib::RayHitInfo
Raycast hit information.
Definition: RayHitInfo.hpp:11
raylib::Material
Material type (generic)
Definition: Material.hpp:14
raylib::Model::Unload
void Unload()
Unload model (including meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:50
raylib::Model::UnloadKeepMeshes
Model & UnloadKeepMeshes()
Unload model (but not meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:61