-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmodel.h
96 lines (83 loc) · 2.66 KB
/
gmodel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef GMODEL_H
#define GMODEL_H
#include <vector>
#include <string>
#include "tgaimage.h"
#include "gmath.h"
#include "ggraphiclibdefine.h"
enum GModelType
{
kMTInvalid,
kMTTriange,
kMTCube,
kMTObj,
};
class GOBJModel {
public:
GOBJModel() = default;
GOBJModel(GModelType modelType, const std::string filename);
void Setup(GModelType modelType, const std::string filename);
int nfaces() const;
GMath::vec3 normal(const int iface, const int nthvert) const;
GMath::vec3 normal(const GMath::vec2 &uv) const;
GMath::vec3 vert(const int i) const;
GMath::vec3 vert(const int iface, const int nthvert) const;
GMath::vec2 uv(const int iface, const int nthvert) const;
TGAColor diffuse(const GMath::vec2 &uv) const;
double specular(const GMath::vec2 &uv) const;
GModelType modelType = GModelType::kMTInvalid;
std::vector<GMath::vec3> verts_;
std::vector<GMath::vec2> uv_;
std::vector<GMath::vec3> norms_;
std::vector<int> facet_vrt_;
std::vector<int> facet_tex_;
std::vector<int> facet_nrm_;
TGAImage diffusemap_;
TGAImage normalmap_;
TGAImage specularmap_;
std::string modelFilePath;
};
struct GGLModel
{
static GGLModel CreateWithObjModel(GOBJModel* objModel, bool init_texture=true);
void init_texture(GMipmapType diff=GMipmapType::kMipmapOff, GMipmapType norm=GMipmapType::kMipmapOff, GMipmapType spec=GMipmapType::kMipmapOff);
int nverts() const;
void* verts_p()
{
return (void*)(verts_.data());
}
void* uv_p()
{
return (void*)(uv_.data());
}
void* norms_p()
{
return (void*)(norms_.data());
}
void* index_p()
{
return (void*)(index_.data());
}
int indexCount()
{
return index_.size();
}
GModelType modelType = GModelType::kMTInvalid;
// opengl use common index buffer
// vertex index == uv index == normal index
std::vector<int> index_;
// opengl vertex count == uv count == normal count
std::vector<GMath::vec3> verts_;
std::vector<GMath::vec2> uv_;
std::vector<GMath::vec3> norms_;
GMipmapType diff_mipmaptype{GMipmapType::kMipmapOff};
std::vector<TGAImage> diffusemap_mipmaps_;
GMipmapType norm_mipmaptype{GMipmapType::kMipmapOff};
std::vector<TGAImage> normalmap_mipmaps_;
GMipmapType spec_mipmaptype{GMipmapType::kMipmapOff};
std::vector<TGAImage> specularmap_mipmaps_;
std::string modelFilePath;
static void load_texture(const std::string texfile, TGAImage &img);
static void load_mipmap(const std::string& modelFilePath, const std::string suffix, std::vector<TGAImage>& mipmaps, int mipmapMaxLevel);
};
#endif // GMODEL_H