added open file ability from the old project to Qt,
texture seams not to open, texture display does not work
This commit is contained in:
		
							
								
								
									
										72
									
								
								MeshViewerQt/Header/FileInterface.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								MeshViewerQt/Header/FileInterface.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| #pragma once | ||||
| #include <fstream> | ||||
| #include <vector> | ||||
| #include <QMatrix4x4> | ||||
|  | ||||
| //TODO: shouldn't be here | ||||
| enum ModelTyp { | ||||
| 	null, | ||||
| 	dynamicMesh, | ||||
| 	cloth, | ||||
| 	bone, | ||||
| 	staticMesh, | ||||
| 	shadowMesh = 6 | ||||
| }; | ||||
|  | ||||
| struct BoundingBox { | ||||
| 	float quaternion[4]; | ||||
| 	float center[3]; | ||||
| 	float extents[3]; | ||||
| }; | ||||
|  | ||||
| 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;	//TODO: should be removed | ||||
| 	std::int32_t renderFlags	= -1;	//TODO: should be removed | ||||
| 	QMatrix4x4 m4x4Translation; | ||||
| 	std::vector<Segment*> segmList; | ||||
| }; | ||||
|  | ||||
| class FileInterface | ||||
| { | ||||
| public: | ||||
| 	FileInterface(const char* path) | ||||
| 		: m_vModels(new std::vector<Model*>) | ||||
| 	{ | ||||
| 		//open file | ||||
| 		m_fsMesh.open(path, std::ios::in | std::ios::binary); | ||||
|  | ||||
| 		if (!m_fsMesh.is_open()) | ||||
| 			throw std::invalid_argument(std::string("file not found: ") += path); | ||||
| 	}; | ||||
|  | ||||
| 	virtual ~FileInterface() | ||||
| 	{ | ||||
| 		// close file | ||||
| 		m_fsMesh.close();  | ||||
|  | ||||
| 		//clean up | ||||
| 		m_vTextureNames.clear(); | ||||
| 	}; | ||||
|  | ||||
| protected: | ||||
| 	std::vector<Model*>* m_vModels; | ||||
| 	std::fstream m_fsMesh; | ||||
| 	std::vector<std::string> m_vTextureNames; | ||||
| 	BoundingBox m_sceneBbox; | ||||
|  | ||||
| 	virtual void import() = 0; | ||||
|  | ||||
| public: | ||||
| 	virtual std::vector<Model*>* getModels() const { return m_vModels; }; | ||||
| 	virtual std::vector<std::string> getTextureNames() const { return m_vTextureNames; }; | ||||
| 	virtual BoundingBox getBoundingBox() const { return m_sceneBbox; }; | ||||
| }; | ||||
| @@ -18,6 +18,7 @@ private: | ||||
| // Functions | ||||
| private: | ||||
| 	void setupWindow(); | ||||
| 	void import(const char* path); | ||||
|  | ||||
| // Slots | ||||
| private slots: | ||||
|   | ||||
| @@ -1,22 +1,6 @@ | ||||
| #pragma once | ||||
| #include <fstream> | ||||
| #include <vector> | ||||
| #include <QMatrix4x4> | ||||
| #include "FileInterface.h" | ||||
|  | ||||
| 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]; | ||||
| @@ -24,36 +8,16 @@ struct ChunkHeader { | ||||
| 	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 | ||||
| class MshFile : public FileInterface | ||||
| { | ||||
| 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; | ||||
| 	virtual void import() override final; | ||||
|  | ||||
| private: | ||||
| 	void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t length); | ||||
|  | ||||
| 	void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList); | ||||
| @@ -67,9 +31,4 @@ private: | ||||
|  | ||||
| 	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; | ||||
| }; | ||||
| @@ -6,7 +6,7 @@ | ||||
| #include <QOpenGlShaderProgram> | ||||
| #include <QOpenGlTexture> | ||||
| #include <QImage> | ||||
| #include "..\Header\MshFile.h" | ||||
| #include "..\Header\FileInterface.h" | ||||
|  | ||||
| struct Vertex { | ||||
| 	GLfloat position[3]; | ||||
| @@ -30,8 +30,8 @@ private: | ||||
| 	QOpenGLShaderProgram* m_program = nullptr; | ||||
|  | ||||
| // Data ======================================== | ||||
| 	std::vector<Model*>* m_vModels = nullptr; | ||||
| 	std::vector<QImage*> m_vTextures; | ||||
| 	std::vector<Model*>* m_vModels		= nullptr; | ||||
| 	std::vector<QImage*>* m_vTextures	= nullptr; | ||||
| 	BoundingBox m_sceneBoundings; | ||||
|  | ||||
| // Transformation ============================== | ||||
| @@ -49,13 +49,13 @@ private: | ||||
|  | ||||
| private: | ||||
| 	virtual void initializeGL() override final; | ||||
| 	virtual void resizeGL(int w, int h) override final; | ||||
| 	virtual void paintGL() override final; | ||||
|  | ||||
| 	void printContextInformation(); | ||||
| 	QMatrix4x4 getModelMatrix(unsigned int index) const; | ||||
| 	QMatrix4x4 getMVPMatrix(unsigned int index) const; | ||||
| 	void deleteData(); | ||||
|  | ||||
| public: | ||||
| 	void setData(std::vector<Model*>* models, std::vector<QImage*> textures); | ||||
| 	void setData(std::vector<Model*>* models, std::vector<QImage*>* textures, BoundingBox bbox); | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Anakin
					Anakin