The small3d framework
Model.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 #include <vulkan/vulkan.h>
14 
15 #define GLM_FORCE_RADIANS
16 #include <glm/glm.hpp>
17 
18 namespace small3d {
25  struct Model {
26 
27  private:
28  // Data read from .obj file
29  std::vector<std::vector<float> > vertices;
30  std::vector<std::vector<int> > facesVertexIndices;
31  std::vector<std::vector<float> > normals;
32  std::vector<std::vector<int> > facesNormalIndices;
33  std::vector<std::vector<float> > textureCoords;
34  std::vector<std::vector<int> > textureCoordsIndices;
35 
36  void loadVertexData();
37  void loadIndexData();
38  void loadNormalsData();
39  void loadTextureCoordsData();
40 
41  // Make sure that no texture coordinate information is lost when the data
42  // buffers get created (vertexData, indexData, normalsData and
43  // textureCoordsData) by realigning the data vectors, in order to ensure
44  // unique vertex - texture coordinates pairs.
45  void correctDataVectors();
46 
47  void clear();
48 
49  public:
50 
55  bool alreadyInGPU = false;
56 
61  VkBuffer positionBuffer;
62 
67  VkDeviceMemory positionBufferMemory;
68 
73  VkBuffer indexBuffer;
74 
79  VkDeviceMemory indexBufferMemory;
80 
85  VkBuffer normalsBuffer;
86 
91  VkDeviceMemory normalsBufferMemory;
92 
97  VkBuffer uvBuffer;
98 
103  VkDeviceMemory uvBufferMemory;
104 
110  uint32_t orientationMemIndex = 0;
111 
116  uint32_t colourMemIndex = 0;
117 
123  std::vector<float> vertexData;
124 
129 
135  std::vector<uint32_t> indexData;
136 
141 
148  std::vector<float> normalsData;
149 
154 
161  std::vector<float> textureCoordsData;
162 
167 
172  std::string textureName = "";
173 
178  bool perspective = false;
179 
180 
185  Model();
186 
192  Model(const std::string fileLocation);
193 
194  };
195 }
VkDeviceMemory positionBufferMemory
Memory for buffer containing vertex positions (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:67
A 3D model, loaded from a Wavefront file.
Definition: Model.hpp:25
VkBuffer normalsBuffer
Normals buffer (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:85
bool alreadyInGPU
Is the model already in GPU memory? (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:55
uint32_t colourMemIndex
Index of model colour in the colour dynamic uniform buffer (Vulkan-specific, avoid direct manipulatio...
Definition: Model.hpp:116
std::vector< uint32_t > indexData
3 column table. Each element refers to a "row" in the vertex data table. Each "row" in the index data...
Definition: Model.hpp:135
VkDeviceMemory uvBufferMemory
Memory for UV coordinates buffer (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:103
VkDeviceMemory normalsBufferMemory
Memory for normals buffer (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:91
bool perspective
True if the model is to be rendered with perspective, False for orthographic rendering.
Definition: Model.hpp:178
std::string textureName
Name of the texture the model will be rendered with. The texture has to have been previously generate...
Definition: Model.hpp:172
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:123
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:148
VkDeviceMemory indexBufferMemory
Memory for index buffer (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:79
int normalsDataByteSize
Size of the normals data, in bytes.
Definition: Model.hpp:153
VkBuffer uvBuffer
UV coordinates buffer (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:97
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:161
int vertexDataByteSize
Size of the vertex data, in bytes.
Definition: Model.hpp:128
VkBuffer positionBuffer
Buffer containing vertex positions (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:61
int indexDataByteSize
Size of the index data, in bytes.
Definition: Model.hpp:140
uint32_t orientationMemIndex
Index of model orientation in the orientation dynamic uniform buffer (Vulkan-specific,...
Definition: Model.hpp:110
Model()
Default constructor.
Definition: Model.cpp:215
int textureCoordsDataByteSize
Size of the texture coordinates data, in bytes.
Definition: Model.hpp:166
VkBuffer indexBuffer
Index buffer (Vulkan-specific, avoid direct manipulation)
Definition: Model.hpp:73