From 4f1ff65f7131bf570e2b7de29baabb692c7009dc Mon Sep 17 00:00:00 2001 From: Anakin Date: Sun, 9 Oct 2016 16:44:35 +0200 Subject: [PATCH] first try to get all MODL and their sub chunks, --- MshViewer/Header/Object.h | 5 +++-- MshViewer/Source/Object.cpp | 34 ++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/MshViewer/Header/Object.h b/MshViewer/Header/Object.h index 0fc8ce0..c513892 100644 --- a/MshViewer/Header/Object.h +++ b/MshViewer/Header/Object.h @@ -17,12 +17,13 @@ public: private: - std::list lChunk; + std::list lChunkMsh2; + std::list lChunkModl; std::fstream fsMesh; private: - void readChunks(); + void loadChunks(std::list &destination, std::streampos start, const char end[5]); public: diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index 2b8607e..270940a 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -14,8 +14,24 @@ Object::Object(const char* path) if (!fsMesh.is_open()) throw std::invalid_argument(std::string("file not found: ") += path); - // get Chunks - readChunks(); + fsMesh.seekg(8); + char tempChunkName[5] = { 0 }; + fsMesh.read(reinterpret_cast(&tempChunkName[0]), sizeof(tempChunkName) - 1); + + if (strcmp(tempChunkName, "MSH2")) + throw std::invalid_argument(std::string("corrupted file MSH2 expected instead of ") += tempChunkName); + + fsMesh.seekg(4, std::ios_base::cur); + + loadChunks(lChunkMsh2, fsMesh.tellg(), "CL1L"); + + for (std::list::iterator it = lChunkMsh2.begin(); it != lChunkMsh2.end(); it++) + { + if (!strcmp("MODL", (*it)->name)) + { + loadChunks(lChunkModl, (*it)->position, "CL1L"); + } + } // close file fsMesh.close(); @@ -27,13 +43,14 @@ Object::~Object() } + ///////////////////////////////////////////////////////////////////////// // private functions -void Object::readChunks() +void Object::loadChunks(std::list& destination, std::streampos start, const char end[5]) { // Jump into Mesh2 - fsMesh.seekg(16, std::ios_base::cur); + fsMesh.seekg(start); do { @@ -43,15 +60,16 @@ void Object::readChunks() fsMesh.read(reinterpret_cast(&tempHeader->size), sizeof(tempHeader->size)); tempHeader->position = fsMesh.tellg(); - lChunk.push_back(tempHeader); + destination.push_back(tempHeader); fsMesh.seekg(tempHeader->size, std::ios_base::cur); - if (!std::strcmp(tempHeader->name, "CL1L")) + if (!std::strcmp(tempHeader->name, end)) break; - } while (!fsMesh.eof()); + } while (fsMesh.good()); + + std::cout << "got all chunks, totaly found: " << destination.size() << std::endl; - std::cout << "got all chunks, totaly found: " << lChunk.size() << std::endl; }