diff --git a/MshViewer/Header/Object.h b/MshViewer/Header/Object.h index 66a0860..595473b 100644 --- a/MshViewer/Header/Object.h +++ b/MshViewer/Header/Object.h @@ -24,8 +24,6 @@ struct Segment { std::uint32_t textureIndex = 0; float* vertex = nullptr; float* uv = nullptr; - std::uint32_t* mesh = nullptr; // not used when using vector - std::uint32_t meshSize = 0; //not used when using vector std::vector*> meshIndices; // indices into vertex array }; diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index 743d5f4..eddd393 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -401,45 +401,6 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list& continue; } - /*if (!strcmp("STRP", (*it)->name)) - { - // jump to the data section and read the size; - fsMesh.seekg((*it)->position); - fsMesh.read(reinterpret_cast(&tempData->meshSize), sizeof(tempData->meshSize)); - - // workaround: ignore everything except unhidden static/dynamic mesh - if (dataDestination->type == null || - dataDestination->type == bone || - dataDestination->type == shadowMesh || - dataDestination->renderFlags == 1) - continue; - - tempData->mesh = new std::uint32_t[tempData->meshSize]; - - for (unsigned int i = 0; i < tempData->meshSize; i += 3) - { - std::uint16_t tempValue[3]; - fsMesh.read(reinterpret_cast(&tempValue[0]), sizeof(std::uint16_t)); - fsMesh.read(reinterpret_cast(&tempValue[1]), sizeof(std::uint16_t)); - fsMesh.read(reinterpret_cast(&tempValue[2]), sizeof(std::uint16_t)); - - if (!(tempValue[0] >> 15 && tempValue[1] >> 15 && !(tempValue[2] >> 15))) - throw std::invalid_argument("invalid file. go and triangulate!"); - - tempValue[0] = (std::uint16_t(tempValue[0] << 1) >> 1); - tempValue[1] = (std::uint16_t(tempValue[1] << 1) >> 1); - - tempData->mesh[i] = (std::uint32_t)tempValue[0]; - tempData->mesh[i + 1] = (std::uint32_t)tempValue[1]; - tempData->mesh[i + 2] = (std::uint32_t)tempValue[2]; - } - - continue; - }*/ - -///////////////////////////////////////////////////////////////////////////////////////// -/////DEV ZONE - if (!strcmp("STRP", (*it)->name)) { // don't get null, bone, shadowMesh and hidden mesh indices @@ -450,13 +411,14 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list& continue; // jump to the data section and read the size; + std::uint32_t tempSize; fsMesh.seekg((*it)->position); - fsMesh.read(reinterpret_cast(&tempData->meshSize), sizeof(tempData->meshSize)); + fsMesh.read(reinterpret_cast(&tempSize), sizeof(tempSize)); int highBitCount(0); std::vector* tempPoly = new std::vector; - for (unsigned int i = 0; i < tempData->meshSize; i++) + for (unsigned int i = 0; i < tempSize; i++) { // ReadData std::uint16_t tempValue; @@ -504,8 +466,6 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list& tempData->meshIndices.erase(tempData->meshIndices.begin()); continue; } - -//////////////////////////////////////////////////////////////////////////////////////// } dataDestination->segmLst.push_back(tempData); } @@ -559,16 +519,26 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list& if (!strcmp("CMSH", (*it)->name)) { + // jump to the data section and read the size; + std::uint32_t tempSize; fsMesh.seekg((*it)->position); - fsMesh.read(reinterpret_cast(&tempData->meshSize), sizeof(tempData->meshSize)); + fsMesh.read(reinterpret_cast(&tempSize), sizeof(tempSize)); - tempData->mesh = new std::uint32_t[tempData->meshSize * 3]; + std::vector* tempPoly; - for (unsigned int i = 0; i < tempData->meshSize; i += 3) + // for every triangle.. + for (unsigned int i = 0; i < tempSize; i += 3) { - fsMesh.read(reinterpret_cast(&tempData->mesh[i]), sizeof(std::uint32_t)); - fsMesh.read(reinterpret_cast(&tempData->mesh[i + 1]), sizeof(std::uint32_t)); - fsMesh.read(reinterpret_cast(&tempData->mesh[i + 2]), sizeof(std::uint32_t)); + tempPoly = new std::vector; + + // ..get the 3 indices and save them + for (int j = 0; j < 3; j++) + { + std::uint32_t tempValue; + fsMesh.read(reinterpret_cast(&tempValue), sizeof(std::uint32_t)); + tempPoly->push_back(tempValue); + } + tempData->meshIndices.push_back(tempPoly); } continue; } diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index 461bb2a..59b1030 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -120,7 +120,6 @@ void OpenGLController::deleteVectors() cursor->segmLst.pop_back(); delete segmCuror->uv; - delete segmCuror->mesh; // not used when using vector delete segmCuror->vertex; while (!segmCuror->meshIndices.empty()) @@ -343,10 +342,10 @@ void OpenGLController::updateScene() // give the MVP to the shader glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]); - glDrawArrays(GL_TRIANGLES, instanceOffset, segIt->meshSize); + glDrawArrays(GL_TRIANGLES, instanceOffset, segIt->meshIndices.size() * 3); // increase the offset - instanceOffset += segIt->meshSize; + instanceOffset += segIt->meshIndices.size() * 3; } } @@ -377,39 +376,6 @@ void OpenGLController::loadMsh(const char * path) // collect vertex data of all models std::vector tempBufferData; - /*for (auto& modIt : vModels) - { - // don't draw bones, nulls, shadow mesh and hidden things - if (modIt->type == null || modIt->type == bone || modIt->type == shadowMesh || modIt->renderFlags == 1) - continue; - - for (auto& segIt : modIt->segmLst) - { - for (unsigned int i = 0; i < segIt->meshSize; i++) - { - Vertex tempVertex; - tempVertex.position[0] = (GLfloat)segIt->vertex[segIt->mesh[i] * 3]; - tempVertex.position[1] = (GLfloat)segIt->vertex[segIt->mesh[i] * 3 + 1]; - tempVertex.position[2] = (GLfloat)segIt->vertex[segIt->mesh[i] * 3 + 2]; - - if (segIt->uv == NULL) - { - tempVertex.uv[0] = 1.0; - tempVertex.uv[1] = 1.0; - } - else - { - tempVertex.uv[0] = (GLfloat)segIt->uv[segIt->mesh[i] * 2]; - tempVertex.uv[1] = (GLfloat)segIt->uv[segIt->mesh[i] * 2 + 1]; - } - - tempBufferData.push_back(tempVertex); - } - } - }*/ - -///////////////////////////////////////////////////////////////////////////////////////// -/////DEV ZONE for (auto& modIt : vModels) // for every model chunk { for (auto& segIt : modIt->segmLst) // for every cluster @@ -441,7 +407,7 @@ void OpenGLController::loadMsh(const char * path) } else if (mshIt->size() > 3) // needs to be triangulated { - //triangulate; + //TODO: triangulate; MessageBox(NULL, "Ooops!", "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR); } else // this shouldn't happen (polygon with less then 3 vertex) @@ -453,8 +419,6 @@ void OpenGLController::loadMsh(const char * path) } } } - // think of delete the data from obj here. It's no longer needed -//////////////////////////////////////////////////////////////////////////////////////// // fill the buffer glBindBuffer(GL_ARRAY_BUFFER, gluiVertexBufferID); diff --git a/MshViewer/main.cpp b/MshViewer/main.cpp index c5c2666..4a166c9 100644 --- a/MshViewer/main.cpp +++ b/MshViewer/main.cpp @@ -17,7 +17,7 @@ int main(int argc, char** argv) else scene = OpenGLController::getInstance(); - scene->loadMsh("..\\Release\\Msh\\cubeTex.msh"); + scene->loadMsh("..\\Release\\Msh\\cluster.msh"); do { scene->updateScene();