Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
model.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2023 Conquer Space
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#pragma once
18
19#include <map>
20#include <memory>
21#include <string>
22#include <vector>
23
24#include <glm/vec2.hpp>
25#include <glm/vec3.hpp>
26
27#include "engine/asset/asset.h"
31
32namespace cqsp::asset {
33struct Material {
34 // Assign each texture to an id
35 std::vector<std::pair<int, asset::Texture*>> textures;
36 std::vector<std::pair<std::string, glm::vec3>> attributes;
37 Material() = default;
39 for (auto& pair : textures) {
40 delete pair.second;
41 }
42 }
43
44 void SetShader(ShaderProgram_t& shader) {
45 for (auto& pair : textures) {
46 shader->bindTexture(pair.first, pair.second->id);
47 }
48 for (auto& pair : attributes) {
49 shader->setVec3(pair.first, pair.second);
50 }
51 }
52};
53
54struct ModelMesh : public engine::Mesh {
56};
57
58typedef std::shared_ptr<ModelMesh> ModelMesh_t;
59
60struct Model : public Asset {
61 std::vector<ModelMesh_t> meshes;
62 std::map<int, Material> materials;
63 glm::vec3 scale;
64 // In theory each material could have a different shader,
65 // but for now we will generalize for the entire model
67 std::string shader_name;
68
70
72
74 for (auto& model_mesh : meshes) {
75 // Set the texture of the model mesh
76 // Set the material
77 // ISS just has a base diffuse color
78 auto& material = materials[model_mesh->material];
79 material.SetShader(shader);
80 model_mesh->Draw();
81 }
82 }
83
84 void Draw() {
85 for (auto& model_mesh : meshes) {
86 // Set the texture of the model mesh
87 // Set the material
88 // ISS just has a base diffuse color
89 auto& material = materials[model_mesh->material];
90 material.SetShader(shader);
91 model_mesh->Draw();
92 }
93 }
94};
95
96struct Vertex {
97 public:
98 static const int MAX_BONE_INFLUENCE = 4;
99 // position
100 glm::vec3 position = glm::vec3(0.f, 0.f, 0.f);
101 // normal
102 glm::vec3 normal = glm::vec3(0.f, 0.f, 0.f);
103 // texCoords
104 glm::vec2 texCoords = glm::vec2(0.f, 0.f);
105 // tangent
106 glm::vec3 tangent = glm::vec3(0.f, 0.f, 0.f);
107 // bitangent
108 glm::vec3 bitangent = glm::vec3(0.f, 0.f, 0.f);
109 //bone indexes which will influence this vertex
111 //weights from each bone
113};
114} // namespace cqsp::asset
The base class for assets.
Definition: asset.h:159
Definition: assetmanager.h:145
Definition: mesh.h:25
Definition: asset.h:30
AssetType
Definition: asset.h:33
std::shared_ptr< ShaderProgram > ShaderProgram_t
The preferred way of using a shader program.
Definition: shader.h:114
@ MODEL
Model prototype.
Definition: assetprototype.h:30
std::shared_ptr< ModelMesh > ModelMesh_t
Definition: model.h:58
Definition: model.h:33
void SetShader(ShaderProgram_t &shader)
Definition: model.h:44
~Material()
Definition: model.h:38
std::vector< std::pair< std::string, glm::vec3 > > attributes
Definition: model.h:36
std::vector< std::pair< int, asset::Texture * > > textures
Definition: model.h:35
Definition: model.h:60
AssetType GetAssetType() override
Definition: model.h:71
std::map< int, Material > materials
Definition: model.h:62
std::vector< ModelMesh_t > meshes
Definition: model.h:61
std::string shader_name
Definition: model.h:67
void Draw(ShaderProgram_t shader)
Definition: model.h:73
ShaderProgram_t shader
Definition: model.h:66
void PostLoad(AssetManager &)
Definition: model.cpp:22
void Draw()
Definition: model.h:84
glm::vec3 scale
Definition: model.h:63
Definition: model.h:54
int material
Definition: model.h:55
Definition: model.h:96
glm::vec2 texCoords
Definition: model.h:104
glm::vec3 normal
Definition: model.h:102
glm::vec3 position
Definition: model.h:100
glm::vec3 bitangent
Definition: model.h:108
static const int MAX_BONE_INFLUENCE
Definition: model.h:98
int m_BoneIDs[MAX_BONE_INFLUENCE]
Definition: model.h:110
float m_Weights[MAX_BONE_INFLUENCE]
Definition: model.h:112
glm::vec3 tangent
Definition: model.h:106