adjust boundingbox (only for SINF)

use else if
This commit is contained in:
Anakin 2016-11-30 17:05:39 +01:00
parent ef2c341a1a
commit 1c0ed61b34
2 changed files with 45 additions and 57 deletions

View File

@ -39,7 +39,6 @@ struct Modl {
Mtyp type = null; Mtyp type = null;
std::int32_t renderFlags = -1; std::int32_t renderFlags = -1;
glm::mat4 m4x4Translation = glm::mat4(1.0f); glm::mat4 m4x4Translation = glm::mat4(1.0f);
Bbox boundingBox;
std::vector<Segment*> segmLst; std::vector<Segment*> segmLst;
}; };
@ -55,6 +54,7 @@ private:
std::vector<Modl*>* vModls; std::vector<Modl*>* vModls;
std::fstream fsMesh; std::fstream fsMesh;
std::vector<std::string> vTextures; std::vector<std::string> vTextures;
Bbox boundingBox;
private: private:
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);

View File

@ -109,12 +109,38 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
{ {
for (auto& it : chunkList) for (auto& it : chunkList)
{ {
if (!strcmp("MATL", it->name)) if (!strcmp("SINF", it->name))
{
std::list<ChunkHeader*> tempSinfChunks;
loadChunks(tempSinfChunks, it->position, it->size);
// evaluate MATL subchunks
for (auto& it : tempSinfChunks)
{
if (!strcmp("BBOX", it->name))
{
fsMesh.seekg(it->position);
// read in the quaternion
for (int i = 0; i < 4; i++)
fsMesh.read(reinterpret_cast<char*>(&boundingBox.quaternion[i]), sizeof(float));
//read in the center
for (int i = 0; i < 3; i++)
fsMesh.read(reinterpret_cast<char*>(&boundingBox.center[i]), sizeof(float));
//read in the extents
for (int i = 0; i < 3; i++)
fsMesh.read(reinterpret_cast<char*>(&boundingBox.extents[i]), sizeof(float));
}
}
}
else if (!strcmp("MATL", it->name))
{ {
// "useless" information how many MATD follow // "useless" information how many MATD follow
fsMesh.seekg(it->position); fsMesh.seekg(it->position);
std::uint32_t tempMatdCount; fsMesh.seekg(sizeof(std::uint32_t), std::ios_base::cur);
fsMesh.read(reinterpret_cast<char*>(&tempMatdCount), sizeof(std::uint32_t));
// get all MATD from MATL list // get all MATD from MATL list
std::list<ChunkHeader*> tempMatlChunks; std::list<ChunkHeader*> tempMatlChunks;
@ -152,11 +178,9 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
tempMatlChunks.pop_front(); tempMatlChunks.pop_front();
delete tempCursor; delete tempCursor;
} }
continue;
} }
if (!strcmp("MODL", it->name)) else if (!strcmp("MODL", it->name))
{ {
Modl* tempModl = new Modl; Modl* tempModl = new Modl;
@ -177,8 +201,6 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
// save Model data // save Model data
vModls->push_back(tempModl); vModls->push_back(tempModl);
continue;
} }
} }
} }
@ -196,7 +218,6 @@ void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
fsMesh.read(buffer, it->size); fsMesh.read(buffer, it->size);
vTextures.back() = buffer; vTextures.back() = buffer;
delete buffer; delete buffer;
continue;
} }
} }
} }
@ -211,10 +232,9 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
std::uint32_t tempType; std::uint32_t tempType;
fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType)); fsMesh.read(reinterpret_cast<char*>(&tempType), sizeof(tempType));
dataDestination->type = (Mtyp)tempType; dataDestination->type = (Mtyp)tempType;
continue;
} }
if (!strcmp("PRNT", it->name)) else if (!strcmp("PRNT", it->name))
{ {
fsMesh.seekg(it->position); fsMesh.seekg(it->position);
char* buffer = new char[it->size]; char* buffer = new char[it->size];
@ -222,10 +242,9 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
fsMesh.read(buffer, it->size); fsMesh.read(buffer, it->size);
dataDestination->parent = buffer; dataDestination->parent = buffer;
delete buffer; delete buffer;
continue;
} }
if (!strcmp("NAME", it->name)) else if (!strcmp("NAME", it->name))
{ {
fsMesh.seekg(it->position); fsMesh.seekg(it->position);
char* buffer = new char[it->size]; char* buffer = new char[it->size];
@ -233,17 +252,15 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
fsMesh.read(buffer, it->size); fsMesh.read(buffer, it->size);
dataDestination->name = buffer; dataDestination->name = buffer;
delete buffer; delete buffer;
continue;
} }
if (!strcmp("FLGS", it->name)) else if (!strcmp("FLGS", it->name))
{ {
fsMesh.seekg(it->position); fsMesh.seekg(it->position);
fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags)); fsMesh.read(reinterpret_cast<char*>(&dataDestination->renderFlags), sizeof(dataDestination->renderFlags));
continue;
} }
if (!strcmp("TRAN", it->name)) else if (!strcmp("TRAN", it->name))
{ {
float tempScale[3]; float tempScale[3];
float tempRotation[4]; float tempRotation[4];
@ -251,6 +268,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
fsMesh.seekg(it->position); fsMesh.seekg(it->position);
//TODO: use loop
fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float)); fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempScale[1]), sizeof(float)); fsMesh.read(reinterpret_cast<char*>(&tempScale[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempScale[2]), sizeof(float)); fsMesh.read(reinterpret_cast<char*>(&tempScale[2]), sizeof(float));
@ -300,10 +318,9 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
glm::vec3(0, 0, 1) glm::vec3(0, 0, 1)
); );
continue;
} }
if (!strcmp("GEOM", it->name)) else if (!strcmp("GEOM", it->name))
{ {
// get all subchunks // get all subchunks
std::list<ChunkHeader*> tempGeomChunks; std::list<ChunkHeader*> tempGeomChunks;
@ -319,8 +336,6 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
tempGeomChunks.pop_front(); tempGeomChunks.pop_front();
delete tempCursor; delete tempCursor;
} }
continue;
} }
} }
} }
@ -329,25 +344,6 @@ void Object::analyseGeomChunks(Modl * dataDestination, std::list<ChunkHeader*>&
{ {
for (auto& it : chunkList) for (auto& it : chunkList)
{ {
if (!strcmp("BBOX", it->name))
{
fsMesh.seekg(it->position);
// 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 // get all subchunks
@ -398,16 +394,14 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
{ {
fsMesh.seekg(it->position); fsMesh.seekg(it->position);
fsMesh.read(reinterpret_cast<char*>(&tempData->textureIndex), sizeof(tempData->textureIndex)); fsMesh.read(reinterpret_cast<char*>(&tempData->textureIndex), sizeof(tempData->textureIndex));
continue;
} }
if (!strcmp("POSL", it->name)) else if (!strcmp("POSL", it->name))
{ {
readVertex(tempData, it->position); readVertex(tempData, it->position);
continue;
} }
/*if (!strcmp("NRML", it->name)) /*else if (!strcmp("NRML", it->name))
{ {
fsMesh.seekg(it->position); fsMesh.seekg(it->position);
std::uint32_t tempSize; std::uint32_t tempSize;
@ -415,16 +409,14 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
// List of normals // List of normals
// long int - 4 - number of normal vectores stored in this list // long int - 4 - number of normal vectores stored in this list
// float[3][] - 12 each - UVW vector for each vertex // float[3][] - 12 each - UVW vector for each vertex
continue;
}*/ }*/
if (!strcmp("UV0L", it->name)) else if (!strcmp("UV0L", it->name))
{ {
readUV(tempData, it->position); readUV(tempData, it->position);
continue;
} }
if (!strcmp("STRP", it->name)) else if (!strcmp("STRP", it->name))
{ {
// don't get null, bone, shadowMesh and hidden mesh indices // don't get null, bone, shadowMesh and hidden mesh indices
if (dataDestination->type == null || if (dataDestination->type == null ||
@ -486,9 +478,9 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
// kick the first element, it's empty as a reason of the algo above; // kick the first element, it's empty as a reason of the algo above;
tempData->meshIndices.erase(tempData->meshIndices.begin()); tempData->meshIndices.erase(tempData->meshIndices.begin());
continue;
} }
} }
dataDestination->segmLst.push_back(tempData); dataDestination->segmLst.push_back(tempData);
} }
@ -524,22 +516,19 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
} }
delete buffer; delete buffer;
continue;
} }
if (!strcmp("CPOS", it->name)) else if (!strcmp("CPOS", it->name))
{ {
readVertex(tempData, it->position); readVertex(tempData, it->position);
continue;
} }
if (!strcmp("CUV0", it->name)) else if (!strcmp("CUV0", it->name))
{ {
readUV(tempData, it->position); readUV(tempData, it->position);
continue;
} }
if (!strcmp("CMSH", it->name)) else if (!strcmp("CMSH", it->name))
{ {
// jump to the data section and read the size; // jump to the data section and read the size;
std::uint32_t tempSize; std::uint32_t tempSize;
@ -562,7 +551,6 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
} }
tempData->meshIndices.push_back(tempPoly); tempData->meshIndices.push_back(tempPoly);
} }
continue;
} }
} }
dataDestination->segmLst.push_back(tempData); dataDestination->segmLst.push_back(tempData);