Commit ef2c341a authored by Anakin's avatar Anakin

using c++11 loops,

reading bbox for each geom,
added some TODO
use the bbox information
parent 5ab2f2ea
......@@ -14,6 +14,12 @@ enum Mtyp {
shadowMesh = 6
};
struct Bbox {
float quaternion[4];
float center[3];
float extents[3];
};
struct ChunkHeader {
char name[5];
std::uint32_t size;
......@@ -33,6 +39,7 @@ struct Modl {
Mtyp type = null;
std::int32_t renderFlags = -1;
glm::mat4 m4x4Translation = glm::mat4(1.0f);
Bbox boundingBox;
std::vector<Segment*> segmLst;
};
......@@ -49,7 +56,6 @@ private:
std::fstream fsMesh;
std::vector<std::string> vTextures;
private:
void loadChunks(std::list<ChunkHeader*> &destination, std::streampos start, const std::uint32_t end);
void analyseMsh2Chunks(std::list<ChunkHeader*> &chunkList);
......
......@@ -107,28 +107,28 @@ 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++)
for (auto& it : chunkList)
{
if (!strcmp("MATL", (*it)->name))
if (!strcmp("MATL", it->name))
{
// "useless" information how many MATD follow
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
std::uint32_t tempMatdCount;
fsMesh.read(reinterpret_cast<char*>(&tempMatdCount), sizeof(std::uint32_t));
// get all MATD from MATL list
std::list<ChunkHeader*> tempMatlChunks;
loadChunks(tempMatlChunks, fsMesh.tellg(), (*it)->size - 4);
loadChunks(tempMatlChunks, fsMesh.tellg(), it->size - 4);
// evaluate MATL subchunks
for (std::list<ChunkHeader*>::iterator it = tempMatlChunks.begin(); it != tempMatlChunks.end(); it++)
for (auto& it : tempMatlChunks)
{
// This shouldn't be anything else than MATD
if (!strcmp("MATD", (*it)->name))
if (!strcmp("MATD", it->name))
{
// get all subchunks from MATD
std::list<ChunkHeader*> tempMatdChunks;
loadChunks(tempMatdChunks, (*it)->position, (*it)->size);
loadChunks(tempMatdChunks, it->position, it->size);
vTextures.push_back("");
......@@ -156,13 +156,13 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
continue;
}
if (!strcmp("MODL", (*it)->name))
if (!strcmp("MODL", it->name))
{
Modl* tempModl = new Modl;
// get all subchunks
std::list<ChunkHeader*> tempChunks;
loadChunks(tempChunks, (*it)->position, (*it)->size);
loadChunks(tempChunks, it->position, it->size);
// evaluate MODL subchunks
analyseModlChunks(tempModl, tempChunks);
......@@ -185,15 +185,15 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
{
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
for (auto& it : chunkList)
{
//TX1D, TX2D, TX3D
if (!strcmp("TX0D", (*it)->name))
if (!strcmp("TX0D", it->name))
{
fsMesh.seekg((*it)->position);
char* buffer = new char[(*it)->size + 1];
fsMesh.seekg(it->position);
char* buffer = new char[it->size + 1];
*buffer = { 0 };
fsMesh.read(buffer, (*it)->size);
fsMesh.read(buffer, it->size);
vTextures.back() = buffer;
delete buffer;
continue;
......@@ -203,53 +203,53 @@ void Object::analyseMatdChunks(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 (auto& it : chunkList)
{
if (!strcmp("MTYP", (*it)->name))
if (!strcmp("MTYP", it->name))
{
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
std::uint32_t tempType;
fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
dataDestination->type = (Mtyp)tempType;
continue;
}
if (!strcmp("PRNT", (*it)->name))
if (!strcmp("PRNT", it->name))
{
fsMesh.seekg((*it)->position);
char* buffer = new char[(*it)->size];
fsMesh.seekg(it->position);
char* buffer = new char[it->size];
*buffer = { 0 };
fsMesh.read(buffer, (*it)->size);
fsMesh.read(buffer, it->size);
dataDestination->parent = buffer;
delete buffer;
continue;
}
if (!strcmp("NAME", (*it)->name))
if (!strcmp("NAME", it->name))
{
fsMesh.seekg((*it)->position);
char* buffer = new char[(*it)->size];
fsMesh.seekg(it->position);
char* buffer = new char[it->size];
*buffer = { 0 };
fsMesh.read(buffer, (*it)->size);
fsMesh.read(buffer, it->size);
dataDestination->name = buffer;
delete buffer;
continue;
}
if (!strcmp("FLGS", (*it)->name))
if (!strcmp("FLGS", it->name))
{
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags));
continue;
}
if (!strcmp("TRAN", (*it)->name))
if (!strcmp("TRAN", it->name))
{
float tempScale[3];
float tempRotation[4];
float tempTrans[3];
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempScale[1]), sizeof(float));
......@@ -260,6 +260,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
fsMesh.read(reinterpret_cast<char*>(&tempRotation[2]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempRotation[3]), sizeof(float));
//TODO: make a function for this
//calculate x,y,z rotation
tempRotation[0] = atan2(2 * (tempRotation[0] * tempRotation[1] + tempRotation[2] * tempRotation[3]),
1 - 2 * (pow(tempRotation[1], 2) + pow(tempRotation[2], 2)));
......@@ -302,11 +303,11 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
continue;
}
if (!strcmp("GEOM", (*it)->name))
if (!strcmp("GEOM", it->name))
{
// get all subchunks
std::list<ChunkHeader*> tempGeomChunks;
loadChunks(tempGeomChunks, (*it)->position, (*it)->size);
loadChunks(tempGeomChunks, it->position, it->size);
// evaluate GEOM subchunks
analyseGeomChunks(dataDestination, tempGeomChunks);
......@@ -326,28 +327,32 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>& chunkList)
{
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
for (auto& it : chunkList)
{
if (!strcmp("BBOX", (*it)->name))
if (!strcmp("BBOX", it->name))
{
fsMesh.seekg((*it)->position);
std::uint32_t tempValue;
fsMesh.read(reinterpret_cast<char*>(&tempValue), sizeof(tempValue));
fsMesh.seekg(it->position);
/*
float[4] 16 Quaternion Rotation in XYZW.
float[3] 12 Center of the BBox.
float[3] 12 Extents of the BBox(width / 2, height / 2, depth / 2).
float 4 Bounding sphere radius.*/
// read in the quaternion
for (int i = 0; i < 4; i++)
fsMesh.read(reinterpret_cast<char*>(&dataDestination->boundingBox.quaternion[i]), sizeof(float));
//read in the center
for (int i = 0; i < 3; i++)
fsMesh.read(reinterpret_cast<char*>(&dataDestination->boundingBox.center[i]), sizeof(float));
//read in the extents
for (int i = 0; i < 3; i++)
fsMesh.read(reinterpret_cast<char*>(&dataDestination->boundingBox.extents[i]), sizeof(float));
continue;
}
if (!strcmp("SEGM", (*it)->name))
if (!strcmp("SEGM", it->name))
{
// get all subchunks
std::list<ChunkHeader*> tempSegmChunks;
loadChunks(tempSegmChunks, (*it)->position, (*it)->size);
loadChunks(tempSegmChunks, it->position, it->size);
// evaluate SEGM subchunks
analyseSegmChunks(dataDestination, tempSegmChunks);
......@@ -362,11 +367,11 @@ void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>&
continue;
}
if (!strcmp("CLTH", (*it)->name))
if (!strcmp("CLTH", it->name))
{
// get all subchunks
std::list<ChunkHeader*> tempClthChunks;
loadChunks(tempClthChunks, (*it)->position, (*it)->size);
loadChunks(tempClthChunks, it->position, it->size);
// evaluate CLTH subchunks
analyseClthChunks(dataDestination, tempClthChunks);
......@@ -387,24 +392,24 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
{
Segment* tempData = new Segment;
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
for (auto& it : chunkList)
{
if (!strcmp("MATI", (*it)->name))
if (!strcmp("MATI", it->name))
{
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
fsMesh.read(reinterpret_cast<char*>(&tempData->textureIndex), sizeof(tempData->textureIndex));
continue;
}
if (!strcmp("POSL", (*it)->name))
if (!strcmp("POSL", it->name))
{
readVertex(tempData, (*it)->position);
readVertex(tempData, it->position);
continue;
}
/*if (!strcmp("NRML", (*it)->name))
/*if (!strcmp("NRML", it->name))
{
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
std::uint32_t tempSize;
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
// List of normals
......@@ -413,13 +418,13 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
continue;
}*/
if (!strcmp("UV0L", (*it)->name))
if (!strcmp("UV0L", it->name))
{
readUV(tempData, (*it)->position);
readUV(tempData, it->position);
continue;
}
if (!strcmp("STRP", (*it)->name))
if (!strcmp("STRP", it->name))
{
// don't get null, bone, shadowMesh and hidden mesh indices
if (dataDestination->type == null ||
......@@ -430,7 +435,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
// jump to the data section and read the size;
std::uint32_t tempSize;
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
int highBitCount(0);
......@@ -472,9 +477,6 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
for (int i = 1; i >= 0; i--)
tempPoly.push_back(saveData[i]);
// save the old vector and set the pointer to the new one
//tempData->meshIndices.push_back(tempPoly);
//tempPoly = newPointer;
} // if high bit set
} // for all values
......@@ -494,14 +496,14 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
{
Segment* tempData = new Segment;
for (std::list<ChunkHeader*>::iterator it = chunkList.begin(); it != chunkList.end(); it++)
for (auto& it : chunkList)
{
if (!strcmp("CTEX", (*it)->name))
if (!strcmp("CTEX", it->name))
{
fsMesh.seekg((*it)->position);
char* buffer = new char[(*it)->size];
fsMesh.seekg(it->position);
char* buffer = new char[it->size];
*buffer = { 0 };
fsMesh.read(buffer, (*it)->size);
fsMesh.read(buffer, it->size);
bool tempFound(false);
......@@ -525,23 +527,23 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
continue;
}
if (!strcmp("CPOS", (*it)->name))
if (!strcmp("CPOS", it->name))
{
readVertex(tempData, (*it)->position);
readVertex(tempData, it->position);
continue;
}
if (!strcmp("CUV0", (*it)->name))
if (!strcmp("CUV0", it->name))
{
readUV(tempData, (*it)->position);
readUV(tempData, it->position);
continue;
}
if (!strcmp("CMSH", (*it)->name))
if (!strcmp("CMSH", it->name))
{
// jump to the data section and read the size;
std::uint32_t tempSize;
fsMesh.seekg((*it)->position);
fsMesh.seekg(it->position);
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
std::vector<uint32_t> tempPoly;
......
......@@ -109,6 +109,7 @@ void OpenGLController::processInit()
void OpenGLController::deleteVectors()
{
//TODO: does .clear() work, too??
if (vModels != NULL)
{
while (!vModels->empty())
......
......@@ -17,7 +17,7 @@ int main(int argc, char** argv)
else
scene = OpenGLController::getInstance();
scene->loadMsh("..\\Release\\Msh\\quadPoly.msh");
scene->loadMsh("..\\Release\\Msh\\multiModTex.msh");
do {
scene->updateScene();
......
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