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