The small3d framework
Model.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 
14 namespace small3d {
21  struct Model {
22 
23  private:
24  // Data read from .obj file
25  std::vector<std::vector<float> > vertices;
26  std::vector<std::vector<int> > facesVertexIndices;
27  std::vector<std::vector<float> > normals;
28  std::vector<std::vector<int> > facesNormalIndices;
29  std::vector<std::vector<float> > textureCoords;
30  std::vector<std::vector<int> > textureCoordsIndices;
31 
32  void loadVertexData();
33  void loadIndexData();
34  void loadNormalsData();
35  void loadTextureCoordsData();
36 
37  // Make sure that no texture coordinate information is lost when the data
38  // buffers get created (vertexData, indexData, normalsData and
39  // textureCoordsData) by realigning the data vectors, in order to ensure
40  // unique vertex - texture coordinates pairs.
41  void correctDataVectors();
42 
43  void clear();
44 
45  public:
46 
51  uint32_t positionBufferObjectId = 0;
52 
57  uint32_t indexBufferObjectId = 0;
58 
63  uint32_t normalsBufferObjectId = 0;
64 
69  uint32_t uvBufferObjectId = 0;
70 
76  std::vector<float> vertexData;
77 
82 
88  std::vector<unsigned int> indexData;
89 
94 
101  std::vector<float> normalsData;
102 
107 
114  std::vector<float> textureCoordsData;
115 
120 
125  Model();
126 
132  Model(const std::string fileLocation);
133 
134  };
135 }
A 3D model, loaded from a Wavefront file.
Definition: Model.hpp:21
uint32_t normalsBufferObjectId
Normals buffer object id. It is suggested not to manipulate this directly.
Definition: Model.hpp:63
uint32_t positionBufferObjectId
Position buffer object id. It is suggested not to manipulate this directly.
Definition: Model.hpp:51
std::vector< float > vertexData
The vertex data. This is an array, which is to be treated as a 4 column table, holding the x,...
Definition: Model.hpp:76
std::vector< float > normalsData
Array, to be treated as a 3 column table. Each "row" contains the x, y and z components of the vector...
Definition: Model.hpp:101
int normalsDataByteSize
Size of the normals data, in bytes.
Definition: Model.hpp:106
std::vector< float > textureCoordsData
Array, to be treated as a 2 column table. Each "row" contains the x and y components of the pixel coo...
Definition: Model.hpp:114
uint32_t indexBufferObjectId
Index buffer object id. It is suggested not to manipulate this directly.
Definition: Model.hpp:57
uint32_t uvBufferObjectId
UV buffer object id. It is suggested not to manipulate this directly.
Definition: Model.hpp:69
int vertexDataByteSize
Size of the vertex data, in bytes.
Definition: Model.hpp:81
std::vector< unsigned int > indexData
3 column table. Each element refers to a "row" in the vertex data table. Each "row" in the index data...
Definition: Model.hpp:88
int indexDataByteSize
Size of the index data, in bytes.
Definition: Model.hpp:93
Model()
Default constructor.
Definition: Model.cpp:194
int textureCoordsDataByteSize
Size of the texture coordinates data, in bytes.
Definition: Model.hpp:119