evaluate most of MODL chunk,

missing GEOM chunk,
This commit is contained in:
Anakin 2016-10-11 13:41:24 +02:00
parent 59446f088f
commit 548150f33e
3 changed files with 124 additions and 5 deletions

View File

@ -2,7 +2,16 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <fstream> #include <fstream>
//#include <windows.h> #include <string>
enum mtyp {
null,
dynamicMesh,
cloth,
bone,
staticMesh,
shadowMesh = 6
};
struct chunkHeader { struct chunkHeader {
char name[5]; char name[5];
@ -10,6 +19,28 @@ struct chunkHeader {
std::streampos position; std::streampos position;
}; };
struct modl {
std::string name;
std::uint32_t size;
std::streampos position;
std::string parent;
mtyp type;
std::uint32_t zeroBaseIndex;
std::uint32_t renderFlags;
struct {
float scale[3];
float rotation[4];
float translation[3];
} tran;
struct {
std::uint32_t type;
float data1;
float data2;
float data3;
} swci;
};
class Object class Object
{ {
public: public:
@ -19,7 +50,7 @@ public:
private: private:
std::list<chunkHeader*> lChunkMsh2; std::list<chunkHeader*> lChunkMsh2;
std::list<std::list<chunkHeader*>*> lChunkModls; std::list<modl*> lModls;
std::fstream fsMesh; std::fstream fsMesh;

View File

@ -33,9 +33,92 @@ Object::Object(const char* path)
{ {
if (!strcmp("MODL", (*it)->name)) if (!strcmp("MODL", (*it)->name))
{ {
std::list<chunkHeader*>* tempModlList = new std::list<chunkHeader*>; modl* tempModl = new modl;
loadChunks(*tempModlList, (*it)->position, (*it)->size); tempModl->size = (*it)->size;
lChunkModls.push_back(tempModlList); tempModl->position = (*it)->position;
std::list<chunkHeader*> tempChunks;
loadChunks(tempChunks, (*it)->position, (*it)->size);
// evaluate MODL subchunks
for (std::list<chunkHeader*>::iterator it = tempChunks.begin(); it != tempChunks.end(); it++)
{
if (!strcmp("MTYP", (*it)->name))
{
fsMesh.seekg((*it)->position);
std::uint32_t tempType;
fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
tempModl->type = (mtyp)tempType;
}
if (!strcmp("MNDX", (*it)->name))
{
fsMesh.seekg((*it)->position);
fsMesh.read(reinterpret_cast<char*>(&tempModl->zeroBaseIndex), sizeof(tempModl->zeroBaseIndex));
}
if (!strcmp("PRNT", (*it)->name))
{
fsMesh.seekg((*it)->position);
char tempName[33] = { 0 };
fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
tempModl->parent = tempName;
}
if (!strcmp("NAME", (*it)->name))
{
fsMesh.seekg((*it)->position);
char tempName[33] = { 0 };
fsMesh.read(reinterpret_cast<char*>(&tempName[0]), (*it)->size > 32 ? 32 : (*it)->size);
tempModl->name = tempName;
}
if (!strcmp("FLGS", (*it)->name))
{
fsMesh.seekg((*it)->position);
fsMesh.read(reinterpret_cast<char*>(&tempModl->renderFlags), sizeof(tempModl->renderFlags));
}
if (!strcmp("TRAN", (*it)->name))
{
fsMesh.seekg((*it)->position);
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.scale[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.scale[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.scale[2]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[2]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.rotation[3]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.translation[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.translation[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempModl->tran.translation[2]), sizeof(float));
}
if (!strcmp("GEOM", (*it)->name))
{
}
if (!strcmp("SWCI", (*it)->name))
{
fsMesh.seekg((*it)->position);
fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.type), sizeof(tempModl->swci.type));
fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.data1), sizeof(tempModl->swci.data1));
fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.data2), sizeof(tempModl->swci.data2));
fsMesh.read(reinterpret_cast<char*>(&tempModl->swci.data3), sizeof(tempModl->swci.data3));
}
}
lModls.push_back(tempModl);
//clean up
while (!tempChunks.empty())
{
chunkHeader* tempCursor = tempChunks.front();
tempChunks.pop_front();
delete tempCursor;
}
} }
} }

View File

@ -9,6 +9,8 @@
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
//goto openGL;
try { try {
Object obj("..\\Release\\Msh\\cube.msh"); Object obj("..\\Release\\Msh\\cube.msh");
} }
@ -21,6 +23,9 @@ int main(int argc, char** argv)
return 0; return 0;
openGL:
OpenGLController *scene = OpenGLController::getInstance(); OpenGLController *scene = OpenGLController::getInstance();
scene->loadMsh("test.msh"); scene->loadMsh("test.msh");