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::map<std::string, std::string> texture_map;
90 std::map<std::string, glm::vec3> base_map;
91};
92
94 public:
95 std::vector<MeshPrototype> prototypes;
96 std::map<std::string, ModelTexturePrototype> texture_map;
97 std::map<int, MaterialPrototype> material_map;
98 std::map<std::string, int> texture_idx_map; // Probably should be per material but
99 // Let's figure that out later
100 std::string shader;
101
103};
104
106 int m_count = 0;
108 const aiScene* scene;
109 std::string asset_path;
110 ModelLoader(const aiScene* _scene, std::string asset_path) : scene(_scene), asset_path(asset_path) {
112 }
113
114 void LoadModel();
115
116 void LoadNode(aiNode* node);
117
118 void LoadMesh(aiMesh* mesh);
119
120 void LoadMaterials();
121
122 void LoadMaterial(int idx, aiMaterial* material);
123
124 bool LoadMaterialTexture(aiMaterial* material, const aiTextureType type, std::string& str);
125};
126
127void LoadModelPrototype(ModelPrototype* prototype, Model* asset);
128
129void LoadModelData(engine::Mesh* mesh, std::vector<Vertex>& vertices, std::vector<unsigned int>& indices);
130} // namespace cqsp::asset
Definition: assetprototype.h:37
Definition: modelloader.h:38
size_t Tell() const
Definition: modelloader.cpp:93
void Flush()
Definition: modelloader.cpp:95
size_t FileSize() const
Definition: modelloader.cpp:94
void Close()
Definition: modelloader.cpp:64
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:75
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:66
Definition: modelloader.h:59
Assimp::IOStream * Open(const char *pFile, const char *pMode) override
Definition: modelloader.cpp:46
IOSystem(VirtualMounter *mount)
Definition: modelloader.cpp:39
void Close(Assimp::IOStream *pFile) override
Definition: modelloader.cpp:42
bool Exists(const char *file) const override
Definition: modelloader.cpp:40
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:155
void LoadModelData(engine::Mesh *mesh, std::vector< Vertex > &vertices, std::vector< unsigned int > &indices)
Definition: modelloader.cpp:196
@ MODEL
Model prototype.
Definition: assetprototype.h:30
std::shared_ptr< IVirtualFile > IVirtualFilePtr
Definition: vfs.h:34
Definition: modelloader.h:88
std::map< std::string, std::string > texture_map
Definition: modelloader.h:89
std::map< std::string, glm::vec3 > base_map
Definition: modelloader.h:90
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:105
int m_count
Definition: modelloader.h:106
void LoadMaterial(int idx, aiMaterial *material)
Definition: modelloader.cpp:304
bool LoadMaterialTexture(aiMaterial *material, const aiTextureType type, std::string &str)
Definition: modelloader.cpp:200
ModelLoader(const aiScene *_scene, std::string asset_path)
Definition: modelloader.h:110
ModelPrototype * model_prototype
Definition: modelloader.h:107
const aiScene * scene
Definition: modelloader.h:108
std::string asset_path
Definition: modelloader.h:109
void LoadMesh(aiMesh *mesh)
Definition: modelloader.cpp:248
void LoadMaterials()
Definition: modelloader.cpp:293
void LoadModel()
Definition: modelloader.cpp:229
void LoadNode(aiNode *node)
Definition: modelloader.cpp:234
Definition: modelloader.h:93
std::map< std::string, int > texture_idx_map
Definition: modelloader.h:98
std::string shader
Definition: modelloader.h:100
int GetPrototypeType()
Definition: modelloader.h:102
std::vector< MeshPrototype > prototypes
Definition: modelloader.h:95
std::map< std::string, ModelTexturePrototype > texture_map
Definition: modelloader.h:96
std::map< int, MaterialPrototype > material_map
Definition: modelloader.h:97
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