2018-10-25 00:19:38 +00:00
|
|
|
#ifndef DUST3D_MESH_LOADER_H
|
|
|
|
#define DUST3D_MESH_LOADER_H
|
2018-03-10 06:57:14 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QOpenGLFunctions>
|
2018-03-20 07:56:49 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <QVector3D>
|
2018-04-26 02:23:22 +00:00
|
|
|
#include <QColor>
|
2018-05-10 09:16:22 +00:00
|
|
|
#include <QImage>
|
2018-04-26 02:23:22 +00:00
|
|
|
#include "positionmap.h"
|
|
|
|
#include "theme.h"
|
2018-10-25 00:19:38 +00:00
|
|
|
#include "outcome.h"
|
2018-03-10 06:57:14 +00:00
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GLfloat posX;
|
|
|
|
GLfloat posY;
|
|
|
|
GLfloat posZ;
|
|
|
|
GLfloat normX;
|
|
|
|
GLfloat normY;
|
|
|
|
GLfloat normZ;
|
2018-03-19 13:56:10 +00:00
|
|
|
GLfloat colorR;
|
|
|
|
GLfloat colorG;
|
|
|
|
GLfloat colorB;
|
2018-05-10 09:16:22 +00:00
|
|
|
GLfloat texU;
|
|
|
|
GLfloat texV;
|
2018-10-04 12:51:01 +00:00
|
|
|
GLfloat metalness;
|
|
|
|
GLfloat roughness;
|
2018-10-09 02:19:12 +00:00
|
|
|
GLfloat tangentX;
|
|
|
|
GLfloat tangentY;
|
|
|
|
GLfloat tangentZ;
|
2018-03-10 06:57:14 +00:00
|
|
|
} Vertex;
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2018-04-26 02:23:22 +00:00
|
|
|
struct TriangulatedFace
|
|
|
|
{
|
2018-11-17 23:02:12 +00:00
|
|
|
int indices[3];
|
2018-04-26 02:23:22 +00:00
|
|
|
QColor color;
|
|
|
|
};
|
|
|
|
|
2018-05-07 17:16:58 +00:00
|
|
|
class MeshLoader
|
2018-03-10 06:57:14 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-10-26 23:04:45 +00:00
|
|
|
MeshLoader(void *meshlite, int meshId, int triangulatedMeshId=-1, QColor defaultColor=Theme::white, const std::vector<QColor> *triangleColors=nullptr, bool smoothNormal=true);
|
2018-10-25 00:19:38 +00:00
|
|
|
MeshLoader(Outcome &outcome);
|
2018-06-11 14:24:25 +00:00
|
|
|
MeshLoader(Vertex *triangleVertices, int vertexNum);
|
|
|
|
MeshLoader(const MeshLoader &mesh);
|
2018-09-18 06:22:29 +00:00
|
|
|
MeshLoader();
|
2018-05-07 17:16:58 +00:00
|
|
|
~MeshLoader();
|
2018-03-19 13:56:10 +00:00
|
|
|
Vertex *triangleVertices();
|
|
|
|
int triangleVertexCount();
|
|
|
|
Vertex *edgeVertices();
|
|
|
|
int edgeVertexCount();
|
2018-03-20 07:56:49 +00:00
|
|
|
const std::vector<QVector3D> &vertices();
|
|
|
|
const std::vector<std::vector<int>> &faces();
|
2018-04-26 02:23:22 +00:00
|
|
|
const std::vector<QVector3D> &triangulatedVertices();
|
|
|
|
const std::vector<TriangulatedFace> &triangulatedFaces();
|
2018-05-10 09:16:22 +00:00
|
|
|
void setTextureImage(QImage *textureImage);
|
|
|
|
const QImage *textureImage();
|
2018-10-09 02:19:12 +00:00
|
|
|
void setNormalMapImage(QImage *normalMapImage);
|
|
|
|
const QImage *normalMapImage();
|
|
|
|
const QImage *metalnessRoughnessAmbientOcclusionImage();
|
|
|
|
void setMetalnessRoughnessAmbientOcclusionImage(QImage *image);
|
|
|
|
bool hasMetalnessInImage();
|
|
|
|
void setHasMetalnessInImage(bool hasInImage);
|
|
|
|
bool hasRoughnessInImage();
|
|
|
|
void setHasRoughnessInImage(bool hasInImage);
|
|
|
|
bool hasAmbientOcclusionInImage();
|
|
|
|
void setHasAmbientOcclusionInImage(bool hasInImage);
|
|
|
|
static float m_defaultMetalness;
|
|
|
|
static float m_defaultRoughness;
|
|
|
|
void exportAsObj(const QString &filename);
|
2018-03-10 06:57:14 +00:00
|
|
|
private:
|
2018-09-18 06:22:29 +00:00
|
|
|
Vertex *m_triangleVertices = nullptr;
|
|
|
|
int m_triangleVertexCount = 0;
|
|
|
|
Vertex *m_edgeVertices = nullptr;
|
|
|
|
int m_edgeVertexCount = 0;
|
2018-03-20 07:56:49 +00:00
|
|
|
std::vector<QVector3D> m_vertices;
|
|
|
|
std::vector<std::vector<int>> m_faces;
|
2018-04-26 02:23:22 +00:00
|
|
|
std::vector<QVector3D> m_triangulatedVertices;
|
|
|
|
std::vector<TriangulatedFace> m_triangulatedFaces;
|
2018-09-18 06:22:29 +00:00
|
|
|
QImage *m_textureImage = nullptr;
|
2018-10-09 02:19:12 +00:00
|
|
|
QImage *m_normalMapImage = nullptr;
|
|
|
|
QImage *m_metalnessRoughnessAmbientOcclusionImage = nullptr;
|
|
|
|
bool m_hasMetalnessInImage = false;
|
|
|
|
bool m_hasRoughnessInImage = false;
|
|
|
|
bool m_hasAmbientOcclusionInImage = false;
|
2018-03-10 06:57:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|