-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.h
More file actions
116 lines (83 loc) · 2.74 KB
/
test.h
File metadata and controls
116 lines (83 loc) · 2.74 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef TEST_H
#define TEST_H
// Qt includes
#include <QString>
#include <QVector>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QOpenGLShaderProgram>
#include <QOpenGLBuffer>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLFunctions>
#include "Model3D/node.h"
#include "Model3D/material.h"
#include "Model3D/vertexdata.h"
#include "transformational.h"
#include "assimp_adapter.h"
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <assimp/Importer.hpp>
class Test : public Transformational
{
public:
Test();
bool loadFromFile(QString filename);
// Transformational interface
public:
void rotate(const QQuaternion &rotation) override;
void translate(const QVector3D &translation) override;
void scale(const float scaleKoef) override;
void setGlobalTransform(const QMatrix4x4 &matrix) override;
void draw(QOpenGLShaderProgram *programm, QOpenGLFunctions *functions) override;
private:
void clear();
void recursiveInitMeshesMaterialsTransforms(
aiMesh **pMeshes,
const aiNode *pNode, QMatrix4x4 transformMatrix);
bool initFromScene(const aiScene *pScene);
void addVertexDatas(const aiMesh* const pMesh,
QVector<VertexData> &vertexDatas,
uint &vertexData_LastIndex);
void addIndexes(const aiMesh* const pMesh,
QVector<uint> &indexes,
uint &indexes_LastIndex);
struct VectorsForShader {
VectorsForShader(aiMesh** meshes, uint size)
: Meshes(meshes), VertexData_LastIndex(0), Indexes_LastIndex(0)
{
uint totalVertexes = 0;
uint totalFaces = 0;
for (int i = 0; i < size; ++i) {
const aiMesh * const pMesh = meshes[i];
totalVertexes += pMesh->mNumVertices;
totalFaces += pMesh->mNumFaces;
}
VertexDatas.resize(totalVertexes);
Indexes.resize(totalFaces * 3);
}
QVector<VertexData> VertexDatas;
uint VertexData_LastIndex;
QVector<uint> Indexes;
uint Indexes_LastIndex;
aiMesh** Meshes;
};
void recursiveProcessAiNodes(
const aiNode* pNode, QMatrix4x4 transformMatrix, VectorsForShader& vectors);
struct Mesh {
Mesh() {}
uint NumVertexes;
uint NumIndexes;
uint BaseIndex;
uint MaterialIndex;
uint TransformMatrixIndex;
};
QOpenGLVertexArrayObject m_VAO;
QOpenGLBuffer m_vertexBuffer;
QOpenGLBuffer m_indexBuffer;
uint m_totalVertexes;
QVector<Mesh> m_meshes;
QVector<uint> m_v;
QVector<Material> m_materials;
QVector<QMatrix4x4> m_transformMatrixes;
};
#endif // TEST_H