raylib-cpp
C++ object-oriented wrapper library for raylib.
Model.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_MODEL_HPP_
26 #define RAYLIB_CPP_INCLUDE_MODEL_HPP_
27 
28 #include <string>
29 
30 #include "./raylib.hpp"
31 #include "./raylib-cpp-utils.hpp"
32 #include "./Mesh.hpp"
33 
34 namespace raylib {
35 class Model : public ::Model {
36  public:
37  Model(::Model model) {
38  set(model);
39  }
40 
41  Model(const std::string& fileName) {
42  set(::LoadModel(fileName.c_str()));
43  }
44 
45  Model(::Mesh mesh) {
46  set(::LoadModelFromMesh(mesh));
47  }
48 
49  ~Model() {
50  Unload();
51  }
52 
53  GETTERSETTER(::Matrix, Transform, transform)
54  GETTERSETTER(int, MeshCount, meshCount)
55  GETTERSETTER(int, MaterialCount, materialCount)
56  GETTERSETTER(int, BoneCount, boneCount)
57 
58  Model& operator=(const ::Model& model) {
59  set(model);
60  return *this;
61  }
62 
63  Model& operator=(const Model& model) {
64  set(model);
65  return *this;
66  }
67 
71  inline void Unload() {
72  ::UnloadModel(*this);
73  }
74 
78  inline Model& UnloadKeepMeshes() {
79  ::UnloadModelKeepMeshes(*this);
80  return *this;
81  }
82 
86  inline Model& SetMeshMaterial(int meshId, int materialId) {
87  ::SetModelMeshMaterial(this, meshId, materialId);
88  return *this;
89  }
90 
94  inline RayHitInfo GetCollision(::Ray ray) const {
95  return ::GetCollisionRayModel(ray, *this);
96  }
97 
101  inline Model& UpdateModelAnimation(::ModelAnimation anim, int frame) {
102  ::UpdateModelAnimation(*this, anim, frame);
103  return *this;
104  }
105 
109  inline bool IsModelAnimationValid(::ModelAnimation anim) const {
110  return ::IsModelAnimationValid(*this, anim);
111  }
112 
113  protected:
114  inline void set(::Model model) {
115  transform = model.transform;
116 
117  meshCount = model.meshCount;
118  materialCount = model.materialCount;
119  meshes = model.meshes;
120  materials = model.materials;
121  meshMaterial = model.meshMaterial;
122 
123  boneCount = model.boneCount;
124  bones = model.bones;
125  bindPose = model.bindPose;
126  }
127 };
128 } // namespace raylib
129 
130 #endif // RAYLIB_CPP_INCLUDE_MODEL_HPP_
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Matrix
Definition: Matrix.hpp:46
raylib::Model::GetCollision
RayHitInfo GetCollision(::Ray ray) const
Get collision info between ray and model.
Definition: Model.hpp:94
raylib::Model::SetMeshMaterial
Model & SetMeshMaterial(int meshId, int materialId)
Set material for a mesh.
Definition: Model.hpp:86
raylib::Ray
Ray type (useful for raycast)
Definition: Ray.hpp:38
raylib::Model::Model
Model(const std::string &fileName)
Definition: Model.hpp:41
raylib::Model::UpdateModelAnimation
Model & UpdateModelAnimation(::ModelAnimation anim, int frame)
Update model animation pose.
Definition: Model.hpp:101
raylib::Mesh
Definition: Mesh.hpp:37
raylib::Model::operator=
Model & operator=(const Model &model)
Definition: Model.hpp:63
raylib::Model
Definition: Model.hpp:35
raylib::Model::Model
Model(::Model model)
Definition: Model.hpp:37
raylib::Model::IsModelAnimationValid
bool IsModelAnimationValid(::ModelAnimation anim) const
Check model animation skeleton match.
Definition: Model.hpp:109
raylib::RayHitInfo
Raycast hit information.
Definition: RayHitInfo.hpp:35
raylib::Model::~Model
~Model()
Definition: Model.hpp:49
raylib::Model::set
void set(::Model model)
Definition: Model.hpp:114
raylib::ModelAnimation
Model animation.
Definition: ModelAnimation.hpp:39
raylib::Model::Model
Model(::Mesh mesh)
Definition: Model.hpp:45
raylib::Model::Unload
void Unload()
Unload model (including meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:71
raylib::Model::UnloadKeepMeshes
Model & UnloadKeepMeshes()
Unload model (but not meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:78