Bomberman
Model.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2021
3 ** Bomberman
4 ** File description:
5 ** Model
6 */
7 
8 #ifndef MODEL_HPP_
9 #define MODEL_HPP_
10 
11 #include "Drawables/Texture.hpp"
13 #include "Model/ModelAnimation.hpp"
14 #include "Shaders/Shaders.hpp"
15 #include <raylib.h>
16 #include "Meshes/AMesh.hpp"
17 #include <vector>
18 #include <optional>
19 #include "Utils/Cache.hpp"
20 
23  class Model: public Drawables::ADrawable3D {
24  public:
25 
26  typedef ::MaterialMapIndex MaterialType;
27 
31  Model(const std::string &filePath, bool lonely = false,
32  std::optional<std::pair<MaterialType, std::string>> texture = std::nullopt,
33  const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1),
34  float rotationAngle = 0,
35  const RAY::Vector3 &position = {0, 0, 0},
36  const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0));
37 
40  Model(const Mesh::AMesh &mesh,
41  std::optional<std::pair<MaterialType, std::string>> texture = std::nullopt,
42  const RAY::Vector3 &scale = RAY::Vector3(1, 1, 1),
43  float rotationAngle = 0,
44  const RAY::Vector3 &position = {0, 0, 0},
45  const RAY::Vector3 &rotationAxis = RAY::Vector3(0, 1, 0));
46 
48  Model(const Model &model) = default;
49 
51  Model& operator=(const Model &model) = default;
52 
54  ~Model() override = default;
55 
57  bool unloadKeepMeshes();
58 
60  bool setAnimation(const RAY::ModelAnimation &animation);
61 
65  bool setTextureToMaterial(MaterialType materialType, const std::string &texture);
66 
68  int getBoneCount() const;
69 
71  Model &setRotationAngle(float roationAngle);
72 
74  float getRotationAngle(void);
75 
77  Model &setRotationAxis(const RAY::Vector3 &rotationAxis);
78 
80  const RAY::Vector3 & getRotationAxis(void);
81 
83  Model &setScale(const RAY::Vector3 &scale);
84 
86  const RAY::Vector3 & getScale(void);
87 
89  void setShader(const RAY::Shader &shader);
90 
92  void resetShader();
93 
94  void drawOn(RAY::Window &) override;
95 
97  void drawWiresOn(RAY::Window &) override;
98 
102 
103  private:
105  std::shared_ptr<::Model> _model;
107  std::unordered_map<MaterialType, Texture> _textureList;
116 
118 
119  INTERNAL:
121  operator ::Model() const;
122 
123  };
124 };
125 #endif /* !Model_HPP_ */
RAY::Vector3
A Three-dimensionnal Vector data type.
Definition: Vector3.hpp:15
RAY::Texture
Object representation of a texture.
Definition: Texture.hpp:19
RAY::Drawables::Drawables3D::Model::_originalShader
::Shader _originalShader
The original shaderId used to disable a shader effect.
Definition: Model.hpp:115
Cache.hpp
RAY::Drawables::Drawables3D::Model::_modelsCache
static RAY::Cache<::Model > _modelsCache
Definition: Model.hpp:117
RAY::Window
Definition: Window.hpp:32
RAY::ModelAnimation
A Holder for Model Animations.
Definition: ModelAnimation.hpp:16
RAY::Drawables::Drawables3D::Model::unloadKeepMeshes
bool unloadKeepMeshes()
Unload model (excluding meshes) from memory (RAM and/or VRAM)
Definition: Model.cpp:57
ADrawable3D.hpp
RAY::Drawables::Drawables3D::Model::resetShader
void resetShader()
Set the original shader (used to disable a shader)
Definition: Model.cpp:158
RAY::Drawables::Drawables3D::Model::_model
std::shared_ptr<::Model > _model
Raw data from raylib.
Definition: Model.hpp:105
RAY::Drawables::Drawables3D::Model::operator=
Model & operator=(const Model &model)=default
A model is assignable.
RAY::Drawables::Drawables3D::Model::MaterialType
::MaterialMapIndex MaterialType
Definition: Model.hpp:26
RAY::Drawables::Drawables3D::Model::getScale
const RAY::Vector3 & getScale(void)
Definition: Model.cpp:123
RAY::Drawables::Drawables3D::Model::setRotationAngle
Model & setRotationAngle(float roationAngle)
Set rotation angle.
Definition: Model.cpp:95
ModelAnimation.hpp
RAY::Drawables::Drawables3D::Model::setScale
Model & setScale(const RAY::Vector3 &scale)
Set Scale.
Definition: Model.cpp:117
RAY::Drawables::Drawables3D::Model::~Model
~Model() override=default
Model destructor, model's data will be deleted if it's the last entity alive.
RAY::Drawables::Drawables3D::Model::_rotationAxis
RAY::Vector3 _rotationAxis
Rotation property.
Definition: Model.hpp:109
RAY::Drawables::ADrawable3D
Abstraction of any three-dimensionnal drawable.
Definition: ADrawable3D.hpp:17
RAY::Drawables::Drawables3D::Model::getRotationAxis
const RAY::Vector3 & getRotationAxis(void)
Definition: Model.cpp:112
RAY::Drawables::Drawables3D::Model::getTextureByMaterial
Texture & getTextureByMaterial(MaterialType materialType)
Definition: Model.cpp:80
RAY::Drawables::Drawables3D::Model::setShader
void setShader(const RAY::Shader &shader)
Set a shader on the model.
Definition: Model.cpp:152
Texture.hpp
RAY::Drawables::Drawables3D
Definition: Circle.cpp:10
AMesh.hpp
RAY::Drawables::Drawables3D::Model::getRotationAngle
float getRotationAngle(void)
Definition: Model.cpp:101
RAY::Drawables::Drawables3D::Model::setRotationAxis
Model & setRotationAxis(const RAY::Vector3 &rotationAxis)
Set Rotation Axis.
Definition: Model.cpp:106
RAY::Drawables::Drawables3D::Model::Model
Model(const std::string &filePath, bool lonely=false, std::optional< std::pair< MaterialType, std::string >> texture=std::nullopt, const RAY::Vector3 &scale=RAY::Vector3(1, 1, 1), float rotationAngle=0, const RAY::Vector3 &position={0, 0, 0}, const RAY::Vector3 &rotationAxis=RAY::Vector3(0, 1, 0))
Create an model, loading a file.
Definition: Model.cpp:24
RAY::Drawables::Drawables3D::Model::drawWiresOn
void drawWiresOn(RAY::Window &) override
Draw model's wires on window.
Definition: Model.cpp:138
RAY::Drawables::Drawables3D::Model::_textureList
std::unordered_map< MaterialType, Texture > _textureList
The list of textures that can be applied to this model.
Definition: Model.hpp:107
RAY::Drawables::Drawables3D::Model::_rotationAngle
float _rotationAngle
Rotation property.
Definition: Model.hpp:111
RAY::Drawables::Drawables3D::Model::setAnimation
bool setAnimation(const RAY::ModelAnimation &animation)
Update model animation pose.
Definition: Model.cpp:63
RAY::Drawables::Drawables3D::Model::drawOn
void drawOn(RAY::Window &) override
Draw drawble on window.
Definition: Model.cpp:128
RAY::Drawables::Drawables3D::Model::setTextureToMaterial
bool setTextureToMaterial(MaterialType materialType, const std::string &texture)
Sets a texture to the Nth material.
Definition: Model.cpp:71
RAY::Drawables::Drawables3D::Model
Basic 3D Model type.
Definition: Model.hpp:23
RAY::Cache
A templated class used to cache ressources, indexed with a string.
Definition: Cache.hpp:23
RAY::Drawables::Drawables3D::Model::_scale
RAY::Vector3 _scale
Scale of the shape.
Definition: Model.hpp:113
RAY::Shader
Definition: Shaders.hpp:16
Shaders.hpp
RAY::Drawables::Drawables3D::Model::getBoneCount
int getBoneCount() const
Definition: Model.cpp:90