2016-12-30 11:36:05 +00:00
|
|
|
#pragma once
|
|
|
|
#include <fstream>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QVector2D>
|
|
|
|
#include <QVector3D>
|
|
|
|
#include <QMatrix4x4>
|
|
|
|
#include <QQuaternion>
|
|
|
|
#include <QOpenGLFunctions>
|
|
|
|
|
|
|
|
|
|
|
|
struct BoundingBox {
|
|
|
|
QQuaternion rotation;
|
|
|
|
QVector3D center;
|
|
|
|
QVector3D extents;
|
|
|
|
};
|
|
|
|
|
2017-01-02 14:07:39 +00:00
|
|
|
struct VertexData
|
|
|
|
{
|
|
|
|
QVector3D position;
|
|
|
|
QVector2D texCoord;
|
|
|
|
};
|
|
|
|
|
2016-12-30 11:36:05 +00:00
|
|
|
struct Segment {
|
|
|
|
std::uint32_t textureIndex = 0;
|
|
|
|
QVector<VertexData> vertices;
|
|
|
|
QVector<GLuint> indices;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Model {
|
|
|
|
std::string name = "";
|
|
|
|
std::string parent = "";
|
|
|
|
QMatrix4x4 m4x4Translation;
|
2017-01-02 15:43:38 +00:00
|
|
|
QQuaternion quadRotation;
|
2016-12-30 11:36:05 +00:00
|
|
|
std::vector<Segment*> segmList;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FileInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit FileInterface(const char* path)
|
|
|
|
: m_models(new QVector<Model*>)
|
|
|
|
, m_textureNames(new QVector<std::string>)
|
|
|
|
{
|
|
|
|
//open file
|
|
|
|
m_file.open(path, std::ios::in | std::ios::binary);
|
|
|
|
|
|
|
|
if (!m_file.is_open())
|
|
|
|
throw std::invalid_argument(std::string("file not found: ") += path);
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~FileInterface()
|
|
|
|
{
|
|
|
|
// close file
|
|
|
|
m_file.close();
|
2016-12-31 12:11:14 +00:00
|
|
|
|
|
|
|
//clean up
|
|
|
|
m_textureNames->clear();
|
|
|
|
delete m_textureNames;
|
|
|
|
|
|
|
|
for (Model* modelIt : *m_models)
|
|
|
|
{
|
|
|
|
for (Segment* segIt : modelIt->segmList)
|
|
|
|
{
|
|
|
|
segIt->indices.clear();
|
|
|
|
segIt->vertices.clear();
|
|
|
|
delete segIt;
|
|
|
|
}
|
|
|
|
modelIt->segmList.clear();
|
|
|
|
|
|
|
|
delete modelIt;
|
|
|
|
}
|
|
|
|
m_models->clear();
|
|
|
|
delete m_models;
|
2016-12-30 11:36:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
QVector<Model*>* m_models;
|
|
|
|
std::fstream m_file;
|
|
|
|
QVector<std::string>* m_textureNames;
|
|
|
|
BoundingBox m_sceneBbox;
|
|
|
|
|
|
|
|
virtual void import() = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual QVector<Model*>* getModels() const { return m_models; };
|
|
|
|
virtual QVector<std::string>* getTextureNames() const { return m_textureNames; };
|
|
|
|
virtual BoundingBox getBoundingBox() const { return m_sceneBbox; };
|
|
|
|
};
|