import msh file,
problems: it is not correctly displayed (vertice and what happend to the texture?) todo: improve the import, remove unused garbage, add move and zoom function
This commit is contained in:
79
QtMeshViewer/Header/FileInterface.h
Normal file
79
QtMeshViewer/Header/FileInterface.h
Normal file
@@ -0,0 +1,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; };
|
||||
};
|
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\Header\FileInterface.h"
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGLShaderProgram>
|
||||
#include <QOpenGLBuffer>
|
||||
@@ -17,6 +17,9 @@ private:
|
||||
QOpenGLBuffer m_indexBuf;
|
||||
QVector<QOpenGLTexture*> m_textures;
|
||||
|
||||
QVector<Model*>* m_models = Q_NULLPTR;
|
||||
QVector<std::string>* m_textureNames = Q_NULLPTR; //TODO: remove, use it local and only hold the textures itself
|
||||
|
||||
void initCubeGeometry();
|
||||
void initTexture();
|
||||
|
||||
|
34
QtMeshViewer/Header/MshFile.h
Normal file
34
QtMeshViewer/Header/MshFile.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include "..\Header\FileInterface.h"
|
||||
|
||||
|
||||
struct ChunkHeader {
|
||||
char name[5];
|
||||
std::uint32_t size;
|
||||
std::streampos position;
|
||||
};
|
||||
|
||||
|
||||
class MshFile : public FileInterface
|
||||
{
|
||||
public:
|
||||
explicit MshFile(const char* path);
|
||||
virtual ~MshFile();
|
||||
|
||||
private:
|
||||
virtual void import() Q_DECL_OVERRIDE Q_DECL_FINAL;
|
||||
|
||||
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t length);
|
||||
|
||||
void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
|
||||
|
||||
void analyseMatdChunks(std::list<ChunkHeader*> &chunkList);
|
||||
|
||||
void analyseModlChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
void analyseGeomChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
void analyseSegmChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
void analyseClthChunks(Model* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||
|
||||
void readVertex(Segment* dataDestination, std::streampos position);
|
||||
void readUV(Segment* dataDestination, std::streampos position);
|
||||
};
|
Reference in New Issue
Block a user