save name, size and position of every chunk under MSH2

This commit is contained in:
Anakin 2016-09-13 19:48:27 +02:00
parent 05b6e4f9ed
commit 443675aeaa
2 changed files with 42 additions and 34 deletions

View File

@ -1,6 +1,13 @@
#pragma once
#include <vector>
#include <list>
#include <fstream>
struct chunkHeader {
char name[5];
int size;
std::streampos position;
};
class Object
{
@ -9,7 +16,13 @@ public:
~Object();
private:
std::list<chunkHeader*> lChunk;
std::fstream fsMesh;
private:
void readChunks();
public:

View File

@ -1,5 +1,4 @@
#include "Object.h"
#include <fstream>
#include <iostream>
@ -10,54 +9,50 @@
Object::Object(const char* path)
{
// open file
std::fstream fsMesh(path, std::ios::in | std::ios::binary);
fsMesh.open(path, std::ios::in | std::ios::binary);
if (!fsMesh.is_open())
throw std::invalid_argument(std::string("file not found: ") += path);
std::uint8_t ui8x4Header[5] = { 0 };
fsMesh.seekg(4, std::ios_base::cur);
std::uint32_t ui32FileSize;
fsMesh.read(reinterpret_cast<char*>(&ui32FileSize), sizeof(ui32FileSize));
fsMesh.seekg(4, std::ios_base::cur);
std::uint32_t ui32MshSize;
fsMesh.read(reinterpret_cast<char*>(&ui32MshSize), sizeof(ui32MshSize));
std::cout << "Hedr " << ui32FileSize << std::endl;
std::cout << "Msh " << ui32MshSize << std::endl;
do
{
char tempChunkName[5] = { 0 };
std::uint32_t tempChunkSize = 0;
fsMesh.read(reinterpret_cast<char*>(&tempChunkName[0]), sizeof(tempChunkName) - 1);
fsMesh.read(reinterpret_cast<char*>(&tempChunkSize), sizeof(tempChunkSize));
std::cout << tempChunkName << " " << tempChunkSize << std::endl;
fsMesh.seekg(tempChunkSize, std::ios_base::cur);
if (!std::strcmp(tempChunkName, "CL1L"))
break;
} while (!fsMesh.eof());
// get Chunks
readChunks();
// close file
fsMesh.close();
}
Object::~Object()
{
//delete Chunk list;
}
/////////////////////////////////////////////////////////////////////////
// private functions
void Object::readChunks()
{
// Jump into Mesh2
fsMesh.seekg(16, std::ios_base::cur);
do
{
chunkHeader* tempHeader = new chunkHeader();
fsMesh.read(reinterpret_cast<char*>(&tempHeader->name[0]), sizeof(tempHeader->name) - 1);
fsMesh.read(reinterpret_cast<char*>(&tempHeader->size), sizeof(tempHeader->size));
tempHeader->position = fsMesh.tellg();
lChunk.push_back(tempHeader);
fsMesh.seekg(tempHeader->size, std::ios_base::cur);
if (!std::strcmp(tempHeader->name, "CL1L"))
break;
} while (!fsMesh.eof());
std::cout << "got all chunks, totaly found: " << lChunk.size() << std::endl;
}
/////////////////////////////////////////////////////////////////////////