Symphony Of Empires
model.hpp
Go to the documentation of this file.
1 // Eng3D - General purpouse game engine
2 // Copyright (C) 2021, Eng3D contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // model.hpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #pragma once
26 
27 #include <vector>
28 #include <string>
29 #include <map>
30 #include <cstdint>
31 
32 #include <glm/vec3.hpp>
33 #include <glm/vec2.hpp>
34 
35 #include "eng3d/mesh.hpp"
36 #include "eng3d/io.hpp"
37 
38 namespace Eng3D {
39  class State;
40  struct Material;
41  namespace OpenGL {
42  class Program;
43  }
44 }
45 
46 class aiMesh;
47 class aiScene;
48 class aiNode;
49 
50 namespace Eng3D {
53  struct SimpleModel : Eng3D::Mesh<glm::vec3, glm::vec2> {
54  SimpleModel(enum Eng3D::MeshMode _mode) : Eng3D::Mesh<glm::vec3, glm::vec2>(_mode) {};
55  ~SimpleModel() = default;
56  SimpleModel(const SimpleModel&) = delete;
57  SimpleModel(SimpleModel&&) noexcept = default;
58  SimpleModel& operator=(const SimpleModel&) = delete;
59  virtual void draw(const Eng3D::OpenGL::Program& shader, int instances = 0) const;
60 
61  std::shared_ptr<Eng3D::Material> material;
62  };
63 
65  struct Model {
66  Model() = default;
67  virtual ~Model() = default;
68  Model(const Model&) = delete;
69  Model(Model&&) noexcept = default;
70  Model& operator=(const Model&) = delete;
71 
72  virtual void draw(const Eng3D::OpenGL::Program& shader, int instances = 0) const {
73  for(auto& model : simple_models)
74  model.draw(shader, instances);
75  }
76 
77 #ifdef E3D_FEATURE_ASSIMP
78  Eng3D::SimpleModel process_simple_model(aiMesh& mesh, const aiScene& scene);
79  void process_node(aiNode& node, const aiScene& scene);
80 #endif
81  std::vector<Eng3D::SimpleModel> simple_models;
82  };
83 
84  class ModelManager {
85  std::map<std::string, std::shared_ptr<Eng3D::Model>> models;
86  Eng3D::State& s;
87  public:
88  ModelManager() = delete;
90  : s{ _s }
91  {
92 
93  }
94  ~ModelManager() = default;
95  std::shared_ptr<Eng3D::Model> load(const std::string& path);
96  std::shared_ptr<Eng3D::Model> load(std::shared_ptr<Eng3D::IO::Asset::Base> asset);
97  };
98 }
~ModelManager()=default
ModelManager(Eng3D::State &_s)
Definition: model.hpp:89
MeshMode
Definition: mesh.hpp:81
void load(GameState &gs, const std::string &savefile_path)
Definition: utils.hpp:35
A definition for a surface/color/texture to be applied to a model.
Definition: material.hpp:40
Packed model - packs both vertices and texcoords into the same buffer.
Definition: mesh.hpp:144
A complex object being composed by many simple objects.
Definition: model.hpp:65
virtual ~Model()=default
std::vector< Eng3D::SimpleModel > simple_models
Definition: model.hpp:81
Model()=default
Model(const Model &)=delete
Model(Model &&) noexcept=default
A simple object - use these to store "simple" objects that MAY repeat.
Definition: model.hpp:53
SimpleModel(SimpleModel &&) noexcept=default
~SimpleModel()=default
std::shared_ptr< Eng3D::Material > material
Definition: model.hpp:61
SimpleModel(const SimpleModel &)=delete
SimpleModel(enum Eng3D::MeshMode _mode)
Definition: model.hpp:54
virtual void draw(const Eng3D::OpenGL::Program &shader, int instances=0) const
Definition: model.cpp:52