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 
71  inline void Unload() {
72  if (meshes != NULL || materials != NULL) {
73  ::UnloadModel(*this);
74  meshes = NULL;
75  materials = NULL;
76  }
77  }
78 
82  inline Model& UnloadKeepMeshes() {
83  ::UnloadModelKeepMeshes(*this);
84  return *this;
85  }
86 
90  inline Model& SetMeshMaterial(int meshId, int materialId) {
91  ::SetModelMeshMaterial(this, meshId, materialId);
92  return *this;
93  }
94 
98  inline RayHitInfo GetCollision(const ::Ray& ray) const {
99  return ::GetCollisionRayModel(ray, *this);
100  }
101 
105  inline Model& UpdateModelAnimation(const ::ModelAnimation& anim, int frame) {
106  ::UpdateModelAnimation(*this, anim, frame);
107  return *this;
108  }
109 
113  inline bool IsModelAnimationValid(const ::ModelAnimation& anim) const {
114  return ::IsModelAnimationValid(*this, anim);
115  }
116 
120  inline Model& Draw(::Vector3 position,
121  float scale = 1.0f,
122  ::Color tint = {255, 255, 255, 255}) {
123  ::DrawModel(*this, position, scale, tint);
124  return *this;
125  }
126 
130  inline Model& Draw(
131  ::Vector3 position,
132  ::Vector3 rotationAxis,
133  float rotationAngle = 0.0f,
134  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
135  ::Color tint = {255, 255, 255, 255}) {
136  ::DrawModelEx(*this, position, rotationAxis, rotationAngle, scale, tint);
137  return *this;
138  }
139 
143  inline Model& DrawWires(::Vector3 position,
144  float scale = 1.0f,
145  ::Color tint = {255, 255, 255, 255}) {
146  ::DrawModelWires(*this, position, scale, tint);
147  return *this;
148  }
149 
153  inline Model& DrawWires(
154  ::Vector3 position,
155  ::Vector3 rotationAxis,
156  float rotationAngle = 0.0f,
157  ::Vector3 scale = {1.0f, 1.0f, 1.0f},
158  ::Color tint = {255, 255, 255, 255}) {
159  ::DrawModelWiresEx(*this, position, rotationAxis, rotationAngle, scale, tint);
160  return *this;
161  }
162 
163  protected:
164  inline void set(const ::Model& model) {
165  transform = model.transform;
166 
167  meshCount = model.meshCount;
168  materialCount = model.materialCount;
169  meshes = model.meshes;
170  materials = model.materials;
171  meshMaterial = model.meshMaterial;
172 
173  boneCount = model.boneCount;
174  bones = model.bones;
175  bindPose = model.bindPose;
176  }
177 };
178 } // namespace raylib
179 
180 #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:105
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:143
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:153
raylib::Model::SetMeshMaterial
Model & SetMeshMaterial(int meshId, int materialId)
Set material for a mesh.
Definition: Model.hpp:90
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:120
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:130
raylib::Model::IsModelAnimationValid
bool IsModelAnimationValid(const ::ModelAnimation &anim) const
Check model animation skeleton match.
Definition: Model.hpp:113
raylib::Vector3
Definition: Vector3.hpp:37
raylib::Mesh
Definition: Mesh.hpp:37
raylib::Color
Definition: Color.hpp:35
raylib::Model
Definition: Model.hpp:35
raylib::Model::set
void set(const ::Model &model)
Definition: Model.hpp:164
raylib::Model::GetCollision
RayHitInfo GetCollision(const ::Ray &ray) const
Get collision info between ray and model.
Definition: Model.hpp:98
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:71
raylib::Model::UnloadKeepMeshes
Model & UnloadKeepMeshes()
Unload model (but not meshes) from memory (RAM and/or VRAM)
Definition: Model.hpp:82