From 10718f226971e68658b72605ea6dde703e60de33 Mon Sep 17 00:00:00 2001 From: Anakin Date: Mon, 23 Jan 2017 12:29:10 +0100 Subject: [PATCH] load tx1d texture --- QtMeshViewer/Header/MshFile.h | 2 +- QtMeshViewer/Source/GeometryEngine.cpp | 8 +++++++- QtMeshViewer/Source/MshFile.cpp | 16 +++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/QtMeshViewer/Header/MshFile.h b/QtMeshViewer/Header/MshFile.h index 61ce382..39a9596 100644 --- a/QtMeshViewer/Header/MshFile.h +++ b/QtMeshViewer/Header/MshFile.h @@ -43,7 +43,7 @@ private: void readVertex(Segment* dataDestination, std::streampos position); void readUV(Segment* dataDestination, std::streampos position); - void loadTexture(QOpenGLTexture*& destination, QString filepath); + void loadTexture(QOpenGLTexture*& destination, QString filepath, QString& filename); QMatrix4x4 getParentMatrix(std::string parent) const; QQuaternion getParentRotation(std::string parent) const; diff --git a/QtMeshViewer/Source/GeometryEngine.cpp b/QtMeshViewer/Source/GeometryEngine.cpp index 28418cd..e2159e5 100644 --- a/QtMeshViewer/Source/GeometryEngine.cpp +++ b/QtMeshViewer/Source/GeometryEngine.cpp @@ -39,7 +39,13 @@ void GeometryEngine::clearData() if (m_materials != Q_NULLPTR) { for (auto it : *m_materials) - delete it.texture0; + { + if (it.texture0 != Q_NULLPTR) + delete it.texture0; + + if (it.texture1 != Q_NULLPTR) + delete it.texture1; + } m_materials->clear(); delete m_materials; } diff --git a/QtMeshViewer/Source/MshFile.cpp b/QtMeshViewer/Source/MshFile.cpp index 0f4147e..eafc798 100644 --- a/QtMeshViewer/Source/MshFile.cpp +++ b/QtMeshViewer/Source/MshFile.cpp @@ -293,7 +293,7 @@ void MshFile::analyseMatdChunks(std::list& chunkList) // load the texture if the name is not empty if (!m_materials->back().tx0d.isEmpty()) - loadTexture(m_materials->back().texture0, m_filepath + "/" + m_materials->back().tx0d); + loadTexture(m_materials->back().texture0, m_filepath, m_materials->back().tx0d); } // texture 1 @@ -307,7 +307,9 @@ void MshFile::analyseMatdChunks(std::list& chunkList) m_materials->back().tx1d = buffer; delete[] buffer; - // TODO: load texture to slot 1, need to change loadTexutre function + if (!m_materials->back().tx1d.isEmpty()) + loadTexture(m_materials->back().texture1, m_filepath, m_materials->back().tx1d); + } // texture 2 @@ -628,7 +630,7 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list m_materials->back().shininess = 10; if (!m_materials->back().tx0d.isEmpty()) - loadTexture(m_materials->back().texture0, m_filepath + "/" + m_materials->back().tx0d); + loadTexture(m_materials->back().texture0, m_filepath, m_materials->back().tx0d); new_segment->textureIndex = m_materials->size() - 1; @@ -713,18 +715,18 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position) m_file.read(F2V(dataDestination->vertices[i].texCoord[j]), sizeof(float)); } -void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath) +void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath, QString& filename) { bool loadSuccess(false); - QImage img = loadTga(filepath, loadSuccess); + QImage img = loadTga(filepath + "/" + filename, loadSuccess); if (!loadSuccess) { - emit sendMessage("WARNING: texture not found or corrupted: " + m_materials->back().name, 1); + emit sendMessage("WARNING: texture not found or corrupted: " + filename, 1); img = QImage(1, 1, QImage::Format_RGB32); img.fill(QColor(m_materials->back().diffuseColor[0] * 255, m_materials->back().diffuseColor[1] * 255, m_materials->back().diffuseColor[2] * 255)); - m_materials->back().tx0d += " *"; + filename += " *"; } // Load image to OglTexture