load tx1d texture

This commit is contained in:
Anakin 2017-01-23 12:29:10 +01:00
parent b2df84eb4c
commit 10718f2269
3 changed files with 17 additions and 9 deletions

View File

@ -43,7 +43,7 @@ private:
void readVertex(Segment* dataDestination, std::streampos position); void readVertex(Segment* dataDestination, std::streampos position);
void readUV(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; QMatrix4x4 getParentMatrix(std::string parent) const;
QQuaternion getParentRotation(std::string parent) const; QQuaternion getParentRotation(std::string parent) const;

View File

@ -39,7 +39,13 @@ void GeometryEngine::clearData()
if (m_materials != Q_NULLPTR) if (m_materials != Q_NULLPTR)
{ {
for (auto it : *m_materials) 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(); m_materials->clear();
delete m_materials; delete m_materials;
} }

View File

@ -293,7 +293,7 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
// load the texture if the name is not empty // load the texture if the name is not empty
if (!m_materials->back().tx0d.isEmpty()) 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 // texture 1
@ -307,7 +307,9 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
m_materials->back().tx1d = buffer; m_materials->back().tx1d = buffer;
delete[] 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 // texture 2
@ -628,7 +630,7 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
m_materials->back().shininess = 10; m_materials->back().shininess = 10;
if (!m_materials->back().tx0d.isEmpty()) 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; 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)); 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); bool loadSuccess(false);
QImage img = loadTga(filepath, loadSuccess); QImage img = loadTga(filepath + "/" + filename, loadSuccess);
if (!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 = 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)); 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 // Load image to OglTexture