now the tool finds the msh2 chunk even if it is not the 2nd behind HEDR,
hence restructured code,
This commit is contained in:
parent
211b406c3d
commit
03553616e7
|
@ -52,14 +52,15 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
std::list<ChunkHeader*> lChunkMsh2;
|
||||
std::list<Modl*> lModls;
|
||||
std::fstream fsMesh;
|
||||
std::list<std::string> lTextures;
|
||||
|
||||
|
||||
private:
|
||||
void setModlDefault(Modl* model);
|
||||
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
|
||||
void analyseMsh2Chunks(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);
|
||||
|
|
|
@ -14,48 +14,47 @@ Object::Object(const char* path)
|
|||
if (!fsMesh.is_open())
|
||||
throw std::invalid_argument(std::string("file not found: ") += path);
|
||||
|
||||
// jump into msh2 todo: search for MSH2 if there is a shadowvolume
|
||||
fsMesh.seekg(8);
|
||||
char tempChunkName[5] = { 0 };
|
||||
fsMesh.read(reinterpret_cast<char*>(&tempChunkName[0]), sizeof(tempChunkName) - 1);
|
||||
// jump to file size information
|
||||
fsMesh.seekg(4);
|
||||
|
||||
if (strcmp(tempChunkName, "MSH2"))
|
||||
throw std::invalid_argument(std::string("corrupted file MSH2 expected instead of ") += tempChunkName);
|
||||
std::uint32_t tempFileSize;
|
||||
std::list<ChunkHeader*> tempMainChunks;
|
||||
|
||||
std::uint32_t tempSize;
|
||||
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
||||
// get all chunks under HEDR
|
||||
fsMesh.read(reinterpret_cast<char*>(&tempFileSize), sizeof(tempFileSize));
|
||||
loadChunks(tempMainChunks, fsMesh.tellg(), tempFileSize);
|
||||
|
||||
// get all sub chunks from MSH2
|
||||
loadChunks(lChunkMsh2, fsMesh.tellg(), tempSize);
|
||||
|
||||
// search for all MODL Chunks
|
||||
for (std::list<ChunkHeader*>::iterator it = lChunkMsh2.begin(); it != lChunkMsh2.end(); it++)
|
||||
// evaluate sub chunks (= find MSH2)
|
||||
for (std::list<ChunkHeader*>::iterator it = tempMainChunks.begin(); it != tempMainChunks.end(); it++)
|
||||
{
|
||||
if (!strcmp("MODL", (*it)->name))
|
||||
if (!strcmp("MSH2", (*it)->name))
|
||||
{
|
||||
Modl* tempModl = new Modl;
|
||||
setModlDefault(tempModl);
|
||||
|
||||
// get all subchunks
|
||||
std::list<ChunkHeader*> tempChunks;
|
||||
loadChunks(tempChunks, (*it)->position, (*it)->size);
|
||||
std::list<ChunkHeader*> tempMsh2Chunks;
|
||||
loadChunks(tempMsh2Chunks, (*it)->position, (*it)->size);
|
||||
|
||||
// evaluate MODL subchunks
|
||||
analyseModlChunks(tempModl, tempChunks);
|
||||
// evaluate MSH2 subchunks
|
||||
analyseMsh2Chunks(tempMsh2Chunks);
|
||||
|
||||
//clean up
|
||||
while (!tempChunks.empty())
|
||||
// clean up
|
||||
while (!tempMsh2Chunks.empty())
|
||||
{
|
||||
ChunkHeader* tempCursor = tempChunks.front();
|
||||
tempChunks.pop_front();
|
||||
ChunkHeader* tempCursor = tempMsh2Chunks.front();
|
||||
tempMsh2Chunks.pop_front();
|
||||
delete tempCursor;
|
||||
}
|
||||
|
||||
// save Model data
|
||||
lModls.push_back(tempModl);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// clean up
|
||||
while (!tempMainChunks.empty())
|
||||
{
|
||||
ChunkHeader* tempCursor = tempMainChunks.front();
|
||||
tempMainChunks.pop_front();
|
||||
delete tempCursor;
|
||||
}
|
||||
|
||||
// close file
|
||||
fsMesh.close();
|
||||
}
|
||||
|
@ -132,6 +131,44 @@ void Object::loadChunks(std::list<ChunkHeader*>& destination, std::streampos sta
|
|||
|
||||
}
|
||||
|
||||
void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
|
||||
{
|
||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
||||
{
|
||||
if (!strcmp("MATL", (*it)->name))
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!strcmp("MODL", (*it)->name))
|
||||
{
|
||||
Modl* tempModl = new Modl;
|
||||
setModlDefault(tempModl);
|
||||
|
||||
// get all subchunks
|
||||
std::list<ChunkHeader*> tempChunks;
|
||||
loadChunks(tempChunks, (*it)->position, (*it)->size);
|
||||
|
||||
// evaluate MODL subchunks
|
||||
analyseModlChunks(tempModl, tempChunks);
|
||||
|
||||
//clean up
|
||||
while (!tempChunks.empty())
|
||||
{
|
||||
ChunkHeader* tempCursor = tempChunks.front();
|
||||
tempChunks.pop_front();
|
||||
delete tempCursor;
|
||||
}
|
||||
|
||||
// save Model data
|
||||
lModls.push_back(tempModl);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||
{
|
||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
||||
|
|
Loading…
Reference in New Issue