Commit 443675ae authored by Anakin's avatar Anakin
Browse files

save name, size and position of every chunk under MSH2

parent 05b6e4f9
#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:
......
#include "Object.h"
#include <fstream>
#include <iostream>
......@@ -10,56 +9,52 @@
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 };
// get Chunks
readChunks();
fsMesh.seekg(4, std::ios_base::cur);
std::uint32_t ui32FileSize;
fsMesh.read(reinterpret_cast<char*>(&ui32FileSize), sizeof(ui32FileSize));
// close file
fsMesh.close();
}
Object::~Object()
{
//delete Chunk list;
}
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;
/////////////////////////////////////////////////////////////////////////
// private functions
void Object::readChunks()
{
// Jump into Mesh2
fsMesh.seekg(16, std::ios_base::cur);
do
{
chunkHeader* tempHeader = new chunkHeader();
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));
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();
std::cout << tempChunkName << " " << tempChunkSize << std::endl;
lChunk.push_back(tempHeader);
fsMesh.seekg(tempChunkSize, std::ios_base::cur);
fsMesh.seekg(tempHeader->size, std::ios_base::cur);
if (!std::strcmp(tempChunkName, "CL1L"))
if (!std::strcmp(tempHeader->name, "CL1L"))
break;
} while (!fsMesh.eof());
fsMesh.close();
}
Object::~Object()
{
std::cout << "got all chunks, totaly found: " << lChunk.size() << std::endl;
}
/////////////////////////////////////////////////////////////////////////
// private functions
/////////////////////////////////////////////////////////////////////////
// public getter
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment