Commit 548150f3 authored by Anakin's avatar Anakin
Browse files

evaluate most of MODL chunk,

missing GEOM chunk,
parent 59446f08
......@@ -2,7 +2,16 @@
#include <vector>
#include <list>
#include <fstream>
//#include <windows.h>
#include <string>
enum mtyp {
null,
dynamicMesh,
cloth,
bone,
staticMesh,
shadowMesh = 6
};
struct chunkHeader {
char name[5];
......@@ -10,6 +19,28 @@ struct chunkHeader {
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
{
public:
......@@ -19,7 +50,7 @@ public:
private:
std::list<chunkHeader*> lChunkMsh2;
std::list<std::list<chunkHeader*>*> lChunkModls;
std::list<modl*> lModls;
std::fstream fsMesh;
......
......@@ -33,9 +33,92 @@ Object::Object(const char* path)
{
if (!strcmp("MODL", (*it)->name))
{
std::list<chunkHeader*>* tempModlList = new std::list<chunkHeader*>;
loadChunks(*tempModlList, (*it)->position, (*it)->size);
lChunkModls.push_back(tempModlList);
modl* tempModl = new modl;
tempModl->size = (*it)->size;
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;
}
}
}
......
......@@ -9,6 +9,8 @@
int main(int argc, char** argv)
{
//goto openGL;
try {
Object obj("..\\Release\\Msh\\cube.msh");
}
......@@ -21,6 +23,9 @@ int main(int argc, char** argv)
return 0;
openGL:
OpenGLController *scene = OpenGLController::getInstance();
scene->loadMsh("test.msh");
......
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