Brenta Engine 1.1
Loading...
Searching...
No Matches
model.hpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2024 Giovanni Santini
5
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 */
26
27#pragma once
28
29#include "mesh.hpp"
30#include "shader.hpp"
31
32#include <assimp/Importer.hpp>
33#include <assimp/postprocess.h>
34#include <assimp/scene.h>
35#include <glad/glad.h>
36#include <string>
37#include <vector>
38
39namespace brenta
40{
41
47class model
48{
49 public:
55 GLint wrapping;
73 GLboolean has_mipmap;
89 bool flip;
90
97 {
98 }
111 model(std::string const &path, GLint wrapping = GL_REPEAT,
112 GLint filtering_min = GL_NEAREST, GLint filtering_mag = GL_LINEAR,
113 GLboolean has_mipmap = GL_TRUE,
114 GLint mipmap_min = GL_LINEAR_MIPMAP_LINEAR,
115 GLint mipmap_mag = GL_LINEAR, bool flip = true);
116
120 class builder;
121
127 void draw(types::shader_name_t shader);
128
129 private:
130 // model data
131 std::vector<mesh> meshes;
132 std::vector<types::texture> textures_loaded;
133 std::string directory;
134
135 void load_model(std::string path);
136 void process_node(aiNode *node, const aiScene *scene);
137 mesh process_mesh(aiMesh *mesh, const aiScene *scene);
138 std::vector<types::texture> load_material_textures(aiMaterial *mat,
139 aiTextureType type,
140 std::string type_name);
141};
142
147{
148 private:
149 std::string path;
150 GLint wrapping = GL_REPEAT;
151 GLint filtering_min = GL_NEAREST;
152 GLint filtering_mag = GL_LINEAR;
153 GLboolean has_mipmap = GL_TRUE;
154 GLint mipmap_min = GL_LINEAR_MIPMAP_LINEAR;
155 GLint mipmap_mag = GL_LINEAR;
156 bool flip = true;
157
158 public:
159 builder &set_path(std::string path);
160 builder &set_wrapping(GLint wrapping);
161 builder &set_filtering_min(GLint filtering_min);
162 builder &set_filtering_mag(GLint filtering_mag);
163 builder &set_has_mipmap(GLboolean has_mipmap);
164 builder &set_mipmap_min(GLint mipmap_min);
165 builder &set_mipmap_mag(GLint mipmap_mag);
166 builder &set_flip(bool flip);
167
168 model build();
169};
170
171} // namespace brenta
The Mesh class represents a 3D model.
Definition mesh.hpp:84
Builder class for Model.
Definition model.hpp:147
Model class.
Definition model.hpp:48
model()
Empty constructor.
Definition model.hpp:96
void draw(types::shader_name_t shader)
Draw the model.
Definition model.cpp:49
bool flip
If the texture should be flipped.
Definition model.hpp:89
GLint filtering_mag
Texture filtering mode.
Definition model.hpp:67
GLboolean has_mipmap
If the texture has a mipmap.
Definition model.hpp:73
GLint wrapping
Texture wrapping mode.
Definition model.hpp:55
GLint mipmap_mag
Mipmap filtering mode.
Definition model.hpp:85
GLint filtering_min
Texture filtering mode.
Definition model.hpp:61
GLint mipmap_min
Mipmap filtering mode.
Definition model.hpp:79
Shader class.
Definition shader.hpp:66