Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

FileInterface.h 1.5 KB
Newer Older
Anakin's avatar
Anakin committed
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
#pragma once
#include <fstream>
#include <QVector>
#include <QVector2D>
#include <QVector3D>
#include <QMatrix4x4>
#include <QQuaternion>
#include <QOpenGLFunctions>


struct VertexData
{
	QVector3D position;
	QVector2D texCoord;
};

enum ModelTyp {
	null,
	dynamicMesh,
	cloth,
	bone,
	staticMesh,
	shadowMesh = 6
};

struct BoundingBox {
	QQuaternion rotation;
	QVector3D center;
	QVector3D extents;
};

struct Segment {
	std::uint32_t textureIndex = 0;
	QVector<VertexData> vertices;
	QVector<GLuint> indices;
};

struct Model {
	std::string name = "";
	std::string parent = "";
	ModelTyp type = null;	//TODO: should be removed
	std::int32_t renderFlags = -1;	//TODO: should be removed
	QMatrix4x4 m4x4Translation;
	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();
	};

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; };
};