diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index 4d5a5b4..316c74b 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -135,9 +135,14 @@ void Object::analyseMsh2Chunks(std::list& chunkList) { 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)); + // get all MATD from MATL list std::list tempMatlChunks; - loadChunks(tempMatlChunks, (*it)->position, (*it)->size); + loadChunks(tempMatlChunks, fsMesh.tellg(), (*it)->size - 4); // evaluate MATL subchunks for (std::list::iterator it = tempMatlChunks.begin(); it != tempMatlChunks.end(); it++) @@ -383,13 +388,13 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list& fsMesh.seekg((*it)->position); std::uint32_t tempIndex; fsMesh.read(reinterpret_cast(&tempIndex), sizeof(tempIndex)); - if (vTextures.size() < tempIndex - 1) + if (vTextures.size() <= tempIndex) { std::cout << "warning texture index <" << tempIndex << "> unknown" << std::endl; dataDestination->texture = ""; continue; } - dataDestination->texture = vTextures[tempIndex - 1]; + dataDestination->texture = vTextures[tempIndex]; continue; } diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index 2515ba3..28ace6e 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -12,7 +12,7 @@ #define VERTEX_SHADER "Shader/VertexTextureShader.mv2shdr" #define FRAGMENT_SHADER "Shader/FragmentTextureShader.mv2shdr" -#define TEXTURE_NAME "Textures/texture32R.tga" +//#define TEXTURE_NAME "Textures/texture32R.tga" ///////////////////////////////////////////////////////////////////////// // public constructor/destructor @@ -281,11 +281,13 @@ void OpenGLController::loadMsh(const char * path) gluiSamplerID = glGetUniformLocation(gluiShaderPrgmID, "textureSampler"); // get data + std::list listTextures; try { Object obj(path); vfVertices = obj.getVertex(); vfUV = obj.getUV(); + listTextures = obj.getTexture(); } catch (std::invalid_argument e) { @@ -296,15 +298,17 @@ void OpenGLController::loadMsh(const char * path) glGenTextures(1, &gluiTextureID); glBindTexture(GL_TEXTURE_2D, gluiTextureID); - std::list listTextures; - - try { if (listTextures.empty()) throw std::invalid_argument("no texture names"); - TextureTGA tempTex(listTextures.front().c_str()); + std::string tempPath = path; + + while (tempPath.back() != '/' && tempPath.back() != '\\') + tempPath.pop_back(); + + TextureTGA tempTex(std::string(tempPath + listTextures.front()).c_str()); glTexImage2D(GL_TEXTURE_2D, 0, tempTex.hasAlpha() ? GL_RGBA : GL_RGB, tempTex.getWidth(), tempTex.getHeight(), 0, tempTex.hasAlpha() ? GL_BGRA : GL_BGR, GL_UNSIGNED_BYTE, tempTex.getData().data()); } catch (std::invalid_argument e) diff --git a/MshViewer/main.cpp b/MshViewer/main.cpp index bcda1d0..fb2fff4 100644 --- a/MshViewer/main.cpp +++ b/MshViewer/main.cpp @@ -28,7 +28,7 @@ openGL: OpenGLController *scene = OpenGLController::getInstance(); - scene->loadMsh("..\\Release\\Msh\\cube.msh"); + scene->loadMsh("..\\Release\\Msh\\cubeTex.msh"); do { scene->updateScene(); diff --git a/Release/Msh/cubeTex.msh b/Release/Msh/cubeTex.msh new file mode 100644 index 0000000..c5ebab9 Binary files /dev/null and b/Release/Msh/cubeTex.msh differ diff --git a/Release/Textures/texture32R.tga b/Release/Msh/texture32R.tga similarity index 100% rename from Release/Textures/texture32R.tga rename to Release/Msh/texture32R.tga