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:
|
private:
|
||||||
|
|
||||||
std::list<ChunkHeader*> lChunkMsh2;
|
|
||||||
std::list<Modl*> lModls;
|
std::list<Modl*> lModls;
|
||||||
std::fstream fsMesh;
|
std::fstream fsMesh;
|
||||||
|
std::list<std::string> lTextures;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setModlDefault(Modl* model);
|
void setModlDefault(Modl* model);
|
||||||
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
|
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 analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||||
void analyseGeomChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
void analyseGeomChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||||
void analyseSegmChunks(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())
|
if (!fsMesh.is_open())
|
||||||
throw std::invalid_argument(std::string("file not found: ") += path);
|
throw std::invalid_argument(std::string("file not found: ") += path);
|
||||||
|
|
||||||
// jump into msh2 todo: search for MSH2 if there is a shadowvolume
|
// jump to file size information
|
||||||
fsMesh.seekg(8);
|
fsMesh.seekg(4);
|
||||||
char tempChunkName[5] = { 0 };
|
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempChunkName[0]), sizeof(tempChunkName) - 1);
|
|
||||||
|
|
||||||
if (strcmp(tempChunkName, "MSH2"))
|
std::uint32_t tempFileSize;
|
||||||
throw std::invalid_argument(std::string("corrupted file MSH2 expected instead of ") += tempChunkName);
|
std::list<ChunkHeader*> tempMainChunks;
|
||||||
|
|
||||||
std::uint32_t tempSize;
|
// get all chunks under HEDR
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
|
fsMesh.read(reinterpret_cast<char*>(&tempFileSize), sizeof(tempFileSize));
|
||||||
|
loadChunks(tempMainChunks, fsMesh.tellg(), tempFileSize);
|
||||||
|
|
||||||
// get all sub chunks from MSH2
|
// evaluate sub chunks (= find MSH2)
|
||||||
loadChunks(lChunkMsh2, fsMesh.tellg(), tempSize);
|
for (std::list<ChunkHeader*>::iterator it = tempMainChunks.begin(); it != tempMainChunks.end(); it++)
|
||||||
|
|
||||||
// search for all MODL Chunks
|
|
||||||
for (std::list<ChunkHeader*>::iterator it = lChunkMsh2.begin(); it != lChunkMsh2.end(); it++)
|
|
||||||
{
|
{
|
||||||
if (!strcmp("MODL", (*it)->name))
|
if (!strcmp("MSH2", (*it)->name))
|
||||||
{
|
{
|
||||||
Modl* tempModl = new Modl;
|
|
||||||
setModlDefault(tempModl);
|
|
||||||
|
|
||||||
// get all subchunks
|
// get all subchunks
|
||||||
std::list<ChunkHeader*> tempChunks;
|
std::list<ChunkHeader*> tempMsh2Chunks;
|
||||||
loadChunks(tempChunks, (*it)->position, (*it)->size);
|
loadChunks(tempMsh2Chunks, (*it)->position, (*it)->size);
|
||||||
|
|
||||||
// evaluate MODL subchunks
|
// evaluate MSH2 subchunks
|
||||||
analyseModlChunks(tempModl, tempChunks);
|
analyseMsh2Chunks(tempMsh2Chunks);
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
while (!tempChunks.empty())
|
while (!tempMsh2Chunks.empty())
|
||||||
{
|
{
|
||||||
ChunkHeader* tempCursor = tempChunks.front();
|
ChunkHeader* tempCursor = tempMsh2Chunks.front();
|
||||||
tempChunks.pop_front();
|
tempMsh2Chunks.pop_front();
|
||||||
delete tempCursor;
|
delete tempCursor;
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
// save Model data
|
|
||||||
lModls.push_back(tempModl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clean up
|
||||||
|
while (!tempMainChunks.empty())
|
||||||
|
{
|
||||||
|
ChunkHeader* tempCursor = tempMainChunks.front();
|
||||||
|
tempMainChunks.pop_front();
|
||||||
|
delete tempCursor;
|
||||||
|
}
|
||||||
|
|
||||||
// close file
|
// close file
|
||||||
fsMesh.close();
|
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)
|
void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& chunkList)
|
||||||
{
|
{
|
||||||
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
|
||||||
|
|
Loading…
Reference in New Issue