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.
modelloader.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 <assimp/postprocess.h>
20#include <assimp/scene.h>
21
22#include <map>
23#include <string>
24#include <vector>
25
26#include <assimp/IOStream.hpp>
27#include <assimp/IOSystem.hpp>
28#include <assimp/Importer.hpp>
29#include <glm/glm.hpp>
30
35
36namespace cqsp::asset {
37class IOSystem;
38class IOStream : public Assimp::IOStream {
39 friend class IOSystem;
40
41 protected:
42 explicit IOStream(IVirtualFilePtr _ivfp) : ivfp(_ivfp) {}
43
45
46 public:
47 size_t Read(void* pvBuffer, size_t pSize, size_t pCount);
48 size_t Write(const void* pvBuffer, size_t pSize, size_t pCount) {
49 return pSize; // We won't ever write because we are only going to open game files
50 }
51 aiReturn Seek(size_t pOffset, aiOrigin pOrigin);
52 size_t Tell() const;
53 size_t FileSize() const;
54 void Flush();
55
56 void Close();
57};
58
59class IOSystem : public Assimp::IOSystem {
61
62 public:
63 explicit IOSystem(VirtualMounter* mount);
64 ~IOSystem() = default;
65
66 bool Exists(const char* file) const override;
67 char getOsSeparator() const override { return '/'; }
68
69 Assimp::IOStream* Open(const char* pFile, const char* pMode) override;
70 void Close(Assimp::IOStream* pFile) override;
71};
72
74 std::vector<Vertex> vertices;
75 std::vector<unsigned int> indices;
76 std::vector<std::string> textures;
78};
79
81 int width;
82 int height;
84
85 unsigned char* texture_data;
86};
87
89 std::vector<std::string> diffuse;
90 std::vector<std::string> specular;
91 std::vector<std::string> ambient;
92 std::vector<std::string> height;
93
94 glm::vec3 base_diffuse;
95 glm::vec3 base_specular;
96 glm::vec3 base_ambient;
97 glm::vec3 base_emissive;
99};
100
102 public:
103 std::vector<MeshPrototype> prototypes;
104 std::map<std::string, ModelTexturePrototype> texture_map;
105 std::map<int, MaterialPrototype> material_map;
107};
108
110 int m_count = 0;
112 const aiScene* scene;
113 std::string asset_path;
114 ModelLoader(const aiScene* _scene, std::string asset_path) : scene(_scene), asset_path(asset_path) {
116 }
117
118 void LoadModel();
119
120 void LoadNode(aiNode* node);
121
122 void LoadMesh(aiMesh* mesh);
123
124 void LoadMaterials();
125
126 void LoadMaterial(int idx, aiMaterial* material);
127
128 void LoadMaterialTextures(aiMaterial* material, const aiTextureType& type, MaterialPrototype& prototype);
129};
130
131void LoadModelPrototype(ModelPrototype* prototype, Model* asset);
132
133void LoadModelData(engine::Mesh* mesh, std::vector<Vertex>& vertices, std::vector<unsigned int>& indices);
134} // namespace cqsp::asset
Definition: assetprototype.h:37
Definition: modelloader.h:38
size_t Tell() const
Definition: modelloader.cpp:91
void Flush()
Definition: modelloader.cpp:93
size_t FileSize() const
Definition: modelloader.cpp:92
void Close()
Definition: modelloader.cpp:62
size_t Write(const void *pvBuffer, size_t pSize, size_t pCount)
Definition: modelloader.h:48
aiReturn Seek(size_t pOffset, aiOrigin pOrigin)
Definition: modelloader.cpp:73
IVirtualFilePtr ivfp
Definition: modelloader.h:44
IOStream(IVirtualFilePtr _ivfp)
Definition: modelloader.h:42
size_t Read(void *pvBuffer, size_t pSize, size_t pCount)
Definition: modelloader.cpp:64
Definition: modelloader.h:59
Assimp::IOStream * Open(const char *pFile, const char *pMode) override
Definition: modelloader.cpp:44
IOSystem(VirtualMounter *mount)
Definition: modelloader.cpp:37
void Close(Assimp::IOStream *pFile) override
Definition: modelloader.cpp:40
bool Exists(const char *file) const override
Definition: modelloader.cpp:38
char getOsSeparator() const override
Definition: modelloader.h:67
VirtualMounter * mount
Definition: modelloader.h:60
Definition: vfs.h:155
Definition: mesh.h:25
lib tracy file(GLOB_RECURSE CPP_FILES *.cpp) list(FILTER CPP_FILES EXCLUDE REGEX ".*main.cpp$") file(GLOB_RECURSE H_FILES *.h) set(SOURCE_FILES $
Definition: CMakeLists.txt:22
Definition: asset.h:30
void LoadModelPrototype(ModelPrototype *prototype, Model *asset)
Definition: modelloader.cpp:153
void LoadModelData(engine::Mesh *mesh, std::vector< Vertex > &vertices, std::vector< unsigned int > &indices)
Definition: modelloader.cpp:190
@ MODEL
Model prototype.
Definition: assetprototype.h:30
std::shared_ptr< IVirtualFile > IVirtualFilePtr
Definition: vfs.h:34
Definition: modelloader.h:88
glm::vec3 base_emissive
Definition: modelloader.h:97
glm::vec3 base_ambient
Definition: modelloader.h:96
glm::vec3 base_diffuse
Definition: modelloader.h:94
glm::vec3 base_specular
Definition: modelloader.h:95
std::vector< std::string > height
Definition: modelloader.h:92
glm::vec3 base_transparent
Definition: modelloader.h:98
std::vector< std::string > ambient
Definition: modelloader.h:91
std::vector< std::string > specular
Definition: modelloader.h:90
std::vector< std::string > diffuse
Definition: modelloader.h:89
Definition: modelloader.h:73
std::vector< unsigned int > indices
Definition: modelloader.h:75
std::vector< Vertex > vertices
Definition: modelloader.h:74
std::vector< std::string > textures
Definition: modelloader.h:76
int material_id
Definition: modelloader.h:77
Definition: modelloader.h:109
int m_count
Definition: modelloader.h:110
void LoadMaterial(int idx, aiMaterial *material)
Definition: modelloader.cpp:309
ModelLoader(const aiScene *_scene, std::string asset_path)
Definition: modelloader.h:114
ModelPrototype * model_prototype
Definition: modelloader.h:111
const aiScene * scene
Definition: modelloader.h:112
std::string asset_path
Definition: modelloader.h:113
void LoadMesh(aiMesh *mesh)
Definition: modelloader.cpp:254
void LoadMaterials()
Definition: modelloader.cpp:299
void LoadModel()
Definition: modelloader.cpp:235
void LoadNode(aiNode *node)
Definition: modelloader.cpp:240
void LoadMaterialTextures(aiMaterial *material, const aiTextureType &type, MaterialPrototype &prototype)
Definition: modelloader.cpp:194
Definition: modelloader.h:101
int GetPrototypeType()
Definition: modelloader.h:106
std::vector< MeshPrototype > prototypes
Definition: modelloader.h:103
std::map< std::string, ModelTexturePrototype > texture_map
Definition: modelloader.h:104
std::map< int, MaterialPrototype > material_map
Definition: modelloader.h:105
Definition: modelloader.h:80
int height
Definition: modelloader.h:82
int width
Definition: modelloader.h:81
unsigned char * texture_data
Definition: modelloader.h:85
int channels
Definition: modelloader.h:83