From abd9070e9061a9cf760b547087b171b35ec49014 Mon Sep 17 00:00:00 2001 From: C-Fu Date: Fri, 20 Jan 2017 11:18:48 +0100 Subject: [PATCH] Read the material name and save it, Shorten transparency evaluation, Need to: - read in the data values, - save the texture name somewhere else, - use the data :D --- QtMeshViewer/Source/MshFile.cpp | 72 ++++++++++++++------------------- 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/QtMeshViewer/Source/MshFile.cpp b/QtMeshViewer/Source/MshFile.cpp index 1325862..906e083 100644 --- a/QtMeshViewer/Source/MshFile.cpp +++ b/QtMeshViewer/Source/MshFile.cpp @@ -217,7 +217,24 @@ void MshFile::analyseMatdChunks(std::list& chunkList) { for (auto& it : chunkList) { - // TODO: don't load default texture, make it NULL + // name + if (!strcmp("NAME", it->name)) + { + m_file.seekg(it->position); + char* buffer = new char[it->size + 1]; + *buffer = { 0 }; + m_file.read(buffer, it->size); + m_materials->back().name = buffer; + delete[] buffer; + } + // TODO: read the data information + // data + else if(!strcmp("DATA", it->name)) + { + + + } + // TODO: use diffuse color instead of default texture //TODO: get information from flags // attributes if (!strcmp("ATRB", it->name)) @@ -235,10 +252,9 @@ void MshFile::analyseMatdChunks(std::list& chunkList) { std::cout << "specular" << std::endl; } - // additive transparency - if ((flag << 1) >> 7) + // additive transparency || hard edged transparency || double-sided transparency || single-sided transparency + if ((flag << 1) >> 7 || (flag << 3) >> 7 || (flag << 4) >> 7 || (flag << 5) >> 7) { - std::cout << "additive transparency" << std::endl; m_materials->back().transparent = true; } // per-pixel lighting @@ -246,24 +262,6 @@ void MshFile::analyseMatdChunks(std::list& chunkList) { std::cout << "per-pixel lighting" << std::endl; } - // hard-edged transparency - if ((flag << 3) >> 7) - { - std::cout << "hard-edged transparency" << std::endl; - m_materials->back().transparent = true; - } - // double-sided transparency - if ((flag << 4) >> 7) - { - std::cout << "double-sided transparency" << std::endl; - m_materials->back().transparent = true; - } - // single-sided transparency - if ((flag << 5) >> 7) - { - std::cout << "single-sided transparency" << std::endl; - m_materials->back().transparent = true; - } // glow if ((flag << 6) >> 7) { @@ -274,10 +272,9 @@ void MshFile::analyseMatdChunks(std::list& chunkList) { std::cout << "emissive" << std::endl; } - } - // texture name + // texture zero else if (!strcmp("TX0D", it->name)) { // get the texture name @@ -285,14 +282,13 @@ void MshFile::analyseMatdChunks(std::list& chunkList) char* buffer = new char[it->size + 1]; *buffer = { 0 }; m_file.read(buffer, it->size); - m_materials->back().name = buffer; + QString texName(buffer); delete[] buffer; - // load the texture - if (m_materials->back().name.isEmpty()) - loadTexture(m_materials->back().texture, ""); - else - loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().name); + // load the texture if the name is not empty + // TODO: save filename for the output + if (!texName.isEmpty()) + loadTexture(m_materials->back().texture, m_filepath + "/" + texName); } } } @@ -686,20 +682,14 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position) void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath) { bool loadSuccess(false); - QImage img; - - if (filepath.isEmpty()) - { - loadSuccess = true; - img = QImage(1, 1, QImage::Format_RGB32); - img.fill(Qt::red); - } - else - img = loadTga(filepath, loadSuccess); + QImage img = loadTga(filepath, loadSuccess); if (!loadSuccess) + { emit sendMessage("WARNING: texture not found or corrupted: " + m_materials->back().name, 1); - + return; + } + // Load image to OglTexture QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());