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(const ::Model& model) {
38  set(model);
39  }
40 
41  Model(const std::string& fileName) {
42  set(::LoadModel(fileName.c_str()));
43  }
44 
45  Model(const ::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(::Mesh *, Meshes, meshes)
57  GETTERSETTER(::Material *, Materials, materials)
58  GETTERSETTER(int *, MeshMaterial, meshMaterial)
59  GETTERSETTER(int, BoneCount, boneCount)
60  GETTERSETTER(::BoneInfo *, Bones, bones)
61  GETTERSETTER(::Transform *, BindPoe, bindPose)
62 
63  Model& operator=(const ::Model& model) {
64  set(model);
65  return *this;
66  }
67 
68  Model& operator=(const Model& model) {
69  set(model);
70  return *this;
71  }
72 
76  inline void Unload() {
77  if (meshes != NULL || materials != NULL) {
78  ::UnloadModel(*this);
79  meshes = NULL;
80  materials = NULL;
81  }
82  }
83 
87  inline Model& UnloadKeepMeshes() {
88  ::UnloadModelKeepMeshes(*this);
89  return *this;
90  }
91 
95  inline Model& SetMeshMaterial(int meshId, int materialId) {
96  ::SetModelMeshMaterial(this, meshId, materialId);
97  return *this;
98  }
99 
103  inline RayHitInfo GetCollision(const ::Ray& ray) const {
104  return ::GetCollisionRayModel(ray, *this);
105  }
106 
110  inline Model& UpdateModelAnimation(const ::ModelAnimation& anim, int frame) {
111  ::UpdateModelAnimation(*this, anim, frame);
112  return *this;
113  }
114 
118  inline bool IsModelAnimationValid(const ::ModelAnimation& anim) const {
119  return ::IsModelAnimationValid(*this, anim);
120  }
121 
125  inline Model& Draw(::Vector3 position,
126  float scale = 1.0f,
127  ::Color tint = {255, 255, 255, 255}) {
128  ::DrawModel(*this, position, scale, tint);
129  return *this;
130  }
131 
135  inline Model& Draw(
136  ::Vector3 position,
137  ::Vector3 rotationAxis,
138  float rotationAngle = 0.0f,
139  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
140  ::Color tint = {255, 255, 255, 255}) {
141  ::DrawModelEx(*this, position, rotationAxis, rotationAngle, scale, tint);
142  return *this;
143  }
144 
148  inline Model& DrawWires(::Vector3 position,
149  float scale = 1.0f,
150  ::Color tint = {255, 255, 255, 255}) {
151  ::DrawModelWires(*this, position, scale, tint);
152  return *this;
153  }
154 
158  inline Model& DrawWires(
159  ::Vector3 position,
160  ::Vector3 rotationAxis,
161  float rotationAngle = 0.0f,
162  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
163  ::Color tint = {255, 255, 255, 255}) {
164  ::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint);
165  return *this;
166  }
167 
168  protected:
169  inline void set(const ::Model& model) {
170  transform = model.transform;
171 
172  meshCount = model.meshCount;
173  materialCount = model.materialCount;
174  meshes = model.meshes;
175  materials = model.materials;
176  meshMaterial = model.meshMaterial;
177 
178  boneCount = model.boneCount;
179  bones = model.bones;
180  bindPose = model.bindPose;
181  }
182 };
183 } // namespace raylib
184 
185 #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::Model
Model(const ::Mesh &mesh)
Definition: Model.hpp:45
raylib::Model::UpdateModelAnimation
Model & UpdateModelAnimation(const ::ModelAnimation &anim, int frame)
Update model animation pose.
Definition: Model.hpp:110
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:148
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:158
raylib::Model::SetMeshMaterial
Model & SetMeshMaterial(int meshId, int materialId)
Set material for a mesh.
Definition: Model.hpp:95
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:125
raylib::Model::Model
Model(const std::string &fileName)
Definition: Model.hpp:41
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:135
raylib::Model::IsModelAnimationValid
bool IsModelAnimationValid(const ::ModelAnimation &anim) const
Check model animation skeleton match.
Definition: Model.hpp:118
raylib::Vector3
Definition: Vector3.hpp:37
raylib::Mesh
Definition: Mesh.hpp:37
raylib::Model::operator=
Model & operator=(const Model &model)
Definition: Model.hpp:68
raylib::Color
Definition: Color.hpp:35
raylib::Model
Definition: Model.hpp:35
raylib::Model::set
void set(const ::Model &model)
Definition: Model.hpp:169
raylib::Model::GetCollision
RayHitInfo GetCollision(const ::Ray &ray) const
Get collision info between ray and model.
Definition: Model.hpp:103
raylib::Model::Model
Model(const ::Model &model)
Definition: Model.hpp:37
raylib::RayHitInfo
Raycast hit information.
Definition: RayHitInfo.hpp:35
raylib::Model::~Model
~Model()
Definition: Model.hpp:49
raylib::Material
Definition: Material.hpp:35
raylib::Model::Unload
void Unload()
Unload model (including meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:76
raylib::Model::UnloadKeepMeshes
Model & UnloadKeepMeshes()
Unload model (but not meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:87