SWBF2-Classic-Msh-Viewer/MshViewer/Header/Object.h

76 lines
1.7 KiB
C
Raw Normal View History

#pragma once
#include <vector>
#include <list>
#include <fstream>
#include <string>
#include <glm\gtc\matrix_transform.hpp>
enum Mtyp {
null,
dynamicMesh,
cloth,
bone,
staticMesh,
shadowMesh = 6
};
struct Bbox {
float quaternion[4];
float center[3];
float extents[3];
};
struct ChunkHeader {
char name[5];
std::uint32_t size;
std::streampos position;
};
2016-09-12 14:49:05 +00:00
2016-11-13 11:15:33 +00:00
struct Segment {
2016-11-13 14:46:52 +00:00
std::uint32_t textureIndex = 0;
2016-11-13 11:15:33 +00:00
float* vertex = nullptr;
float* uv = nullptr;
2016-11-26 14:39:59 +00:00
std::vector<std::vector<std::uint32_t>> meshIndices; // indices into vertex array
2016-11-13 11:15:33 +00:00
};
struct Modl {
2016-11-12 11:05:03 +00:00
std::string name = "";
std::string parent = "";
Mtyp type = null;
std::int32_t renderFlags = -1;
glm::mat4 m4x4Translation = glm::mat4(1.0f);
2016-11-13 11:15:33 +00:00
std::vector<Segment*> segmLst;
};
class Object
{
public:
Object(const char* path);
~Object();
private:
std::vector<Modl*>* vModls;
std::fstream fsMesh;
std::vector<std::string> vTextures;
Bbox boundingBox;
private:
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
2016-10-22 12:05:46 +00:00
void analyseMatdChunks(std::list<ChunkHeader*> &chunkList);
void analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
void analyseGeomChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
void analyseSegmChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
void analyseClthChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
2016-11-13 11:15:33 +00:00
void readVertex(Segment* dataDestination, std::streampos position);
void readUV(Segment* dataDestination, std::streampos position);
public:
std::vector<Modl*>* getModels() const;
2016-11-13 14:46:52 +00:00
std::vector<std::string> getTextureList() const;
Bbox getBoundgBox() const;
};