copied from the old Ppoject:
shaders, object class Modified to use better names and use Qt things
This commit is contained in:
75
MeshViewerQt/Header/MshFile.h
Normal file
75
MeshViewerQt/Header/MshFile.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <QMatrix4x4>
|
||||
|
||||
enum ModelTyp {
|
||||
null,
|
||||
dynamicMesh,
|
||||
cloth,
|
||||
bone,
|
||||
staticMesh,
|
||||
shadowMesh = 6
|
||||
};
|
||||
|
||||
struct BoundingBox {
|
||||
float quaternion[4];
|
||||
float center[3];
|
||||
float extents[3];
|
||||
};
|
||||
|
||||
struct ChunkHeader {
|
||||
char name[5];
|
||||
std::uint32_t size;
|
||||
std::streampos position;
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
std::uint32_t textureIndex = 0;
|
||||
float* vertex = nullptr;
|
||||
float* uv = nullptr;
|
||||
std::vector<std::vector<std::uint32_t>> polyIndices; // indices into vertex array
|
||||
};
|
||||
|
||||
struct Model {
|
||||
std::string name = "";
|
||||
std::string parent = "";
|
||||
ModelTyp type = null;
|
||||
std::int32_t renderFlags = -1;
|
||||
QMatrix4x4 m4x4Translation;
|
||||
std::vector<Segment*> segmList;
|
||||
};
|
||||
|
||||
|
||||
class MshFile
|
||||
{
|
||||
public:
|
||||
MshFile(const char* path);
|
||||
~MshFile();
|
||||
|
||||
private:
|
||||
std::vector<Model*>* m_vModels;
|
||||
std::fstream m_fsMesh;
|
||||
std::vector<std::string> m_vTextureNames;
|
||||
BoundingBox m_sceneBbox;
|
||||
|
||||
private:
|
||||
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);
|
||||
|
||||
public:
|
||||
std::vector<Model*>* getModels() const;
|
||||
std::vector<std::string> getTextureNames() const;
|
||||
BoundingBox getBoundingBox() const;
|
||||
};
|
@@ -1,10 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <QOpenGLWidget>
|
||||
#include <QOpenGLFunctions>
|
||||
#include <QOpenGLBuffer>
|
||||
#include <QOPenGLVertexArrayObject>
|
||||
#include <QOpenGlShaderProgram>
|
||||
#include "..\Header\MshFile.h"
|
||||
|
||||
struct Vertex {
|
||||
GLfloat position[3];
|
||||
GLfloat uv[2];
|
||||
};
|
||||
|
||||
struct textureData {
|
||||
bool alpha;
|
||||
std::uint32_t width;
|
||||
std::uint32_t height;
|
||||
std::vector<std::uint8_t>* data;
|
||||
};
|
||||
|
||||
class OpenGlViewer : public QOpenGLWidget, protected QOpenGLFunctions
|
||||
{
|
||||
@@ -15,17 +27,37 @@ public:
|
||||
~OpenGlViewer();
|
||||
|
||||
private:
|
||||
QOpenGLBuffer mVertexBuffer;
|
||||
QOpenGLVertexArrayObject mVertexArray;
|
||||
QOpenGLShaderProgram* mProgram = nullptr;
|
||||
// OpenGL ======================================
|
||||
QOpenGLBuffer m_vertexBuffer;
|
||||
QOpenGLVertexArrayObject m_vertexArray;
|
||||
QOpenGLShaderProgram* m_program = nullptr;
|
||||
|
||||
// Data ========================================
|
||||
std::vector<Model*>* m_vModels = nullptr;
|
||||
std::vector<textureData*> m_vTextures;
|
||||
BoundingBox m_sceneBoundings;
|
||||
|
||||
// Transformation ==============================
|
||||
float m_fRotX = 0;
|
||||
float m_fRotY = 0;
|
||||
float m_fRotZ = 0;
|
||||
float m_fTranX = 0;
|
||||
float m_fTranY = 0;
|
||||
float m_fTranZ = 0;
|
||||
|
||||
// Camera ======================================
|
||||
float m_fFOV = 45.0f;
|
||||
float m_fMinView = 0.1f;
|
||||
float m_fMaxView = 100.0f;
|
||||
|
||||
private:
|
||||
void printContextInformation();
|
||||
|
||||
protected:
|
||||
virtual void initializeGL() override final;
|
||||
virtual void resizeGL(int w, int h) override final;
|
||||
virtual void paintGL() override final;
|
||||
|
||||
void printContextInformation();
|
||||
void deleteData();
|
||||
|
||||
public:
|
||||
void setData(std::vector<Model*>* models, std::vector<textureData*> textures);
|
||||
};
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#ifndef VERTEX_H
|
||||
#define VERTEX_H
|
||||
#pragma once
|
||||
|
||||
#include <QVector3D>
|
||||
|
||||
@@ -51,5 +50,3 @@ void inline Vertex::setColor(const QVector3D& color) { m_color = color; }
|
||||
Q_DECL_CONSTEXPR inline int Vertex::positionOffset() { return offsetof(Vertex, m_position); }
|
||||
Q_DECL_CONSTEXPR inline int Vertex::colorOffset() { return offsetof(Vertex, m_color); }
|
||||
Q_DECL_CONSTEXPR inline int Vertex::stride() { return sizeof(Vertex); }
|
||||
|
||||
#endif // VERTEX_H
|
@@ -5,6 +5,4 @@
|
||||
#define WINDOW_HEIGHT 480
|
||||
|
||||
#define DEFAULT_STATUS_MESSAGE "Mesh Viewer pre alpha by Anakin"
|
||||
#define DEFAULT_MAJOR_VERSION 4
|
||||
#define DEFAULT_MINOR_VERSION 5
|
||||
#define DEAFAULT_BACKGROUND 0.5000f, 0.8000f, 1.0000f, 0.0000f
|
||||
|
||||
|
Reference in New Issue
Block a user