read tx1d tx2d tx3d texture names and print to info window

This commit is contained in:
Anakin
2017-01-23 12:17:26 +01:00
parent 2ed9e475ce
commit b2df84eb4c
6 changed files with 89 additions and 29 deletions

View File

@@ -21,7 +21,7 @@ GeometryEngine::GeometryEngine(QObject *parent)
GeometryEngine::~GeometryEngine()
{
clearData();
delete m_defaultMaterial->texture;
delete m_defaultMaterial->texture0;
delete m_defaultMaterial;
}
@@ -39,7 +39,7 @@ void GeometryEngine::clearData()
if (m_materials != Q_NULLPTR)
{
for (auto it : *m_materials)
delete it.texture;
delete it.texture0;
m_materials->clear();
delete m_materials;
}
@@ -182,9 +182,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
QVector3D specularColor;
// bind the correct texture
if (it.textureIndex < m_materials->size() && m_materials->at(it.textureIndex).texture != Q_NULLPTR)
if (it.textureIndex < m_materials->size() && m_materials->at(it.textureIndex).texture0 != Q_NULLPTR)
{
m_materials->at(it.textureIndex).texture->bind();
m_materials->at(it.textureIndex).texture0->bind();
tmp_transparent = m_materials->at(it.textureIndex).transparent;
tmp_specular = m_materials->at(it.textureIndex).flags[7];
shininess = m_materials->at(it.textureIndex).shininess;
@@ -192,7 +192,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
}
else
{
m_defaultMaterial->texture->bind();
m_defaultMaterial->texture0->bind();
tmp_transparent = m_defaultMaterial->transparent;
}
// Set model matrix

View File

@@ -210,17 +210,37 @@ void MainWindow::setFileInfo(QString name, QVector<Material>* materials, int ver
m_fileInfo += QByteArray::number(triangle);
m_fileInfo += "<detail>";
//TODO: mark not opened textures
//TODO: add more information
for (auto& it : *materials)
{
m_fileInfo += it.name;
m_fileInfo += "\n";
m_fileInfo += "TX0D:\t\t";
if (it.texture == NULL)
if (it.tx0d.isEmpty())
m_fileInfo += "-";
m_fileInfo += it.textureName;
else
m_fileInfo += it.tx0d;
m_fileInfo += "\n";
m_fileInfo += "TX1D:\t\t";
if (it.tx1d.isEmpty())
m_fileInfo += "-";
else
m_fileInfo += it.tx1d;
m_fileInfo += "\n";
m_fileInfo += "TX2D:\t\t";
if (it.tx2d.isEmpty())
m_fileInfo += "-";
else
m_fileInfo += it.tx2d;
m_fileInfo += "\n";
m_fileInfo += "TX3D:\t\t";
if (it.tx3d.isEmpty())
m_fileInfo += "-";
else
m_fileInfo += it.tx3d;
m_fileInfo += "\n";
m_fileInfo += "Flags:\t\t";

View File

@@ -249,7 +249,6 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
m_file.read(F2V(m_materials->back().shininess), sizeof(float));
}
// TODO: evaluate specular, gloss,.. and save values
// attributes
else if (!strcmp("ATRB", it->name))
{
@@ -281,7 +280,7 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
}
// texture zero
// texture 0
else if (!strcmp("TX0D", it->name))
{
// get the texture name
@@ -289,12 +288,50 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
char* buffer = new char[it->size + 1];
*buffer = { 0 };
m_file.read(buffer, it->size);
m_materials->back().textureName = buffer;
m_materials->back().tx0d = buffer;
delete[] buffer;
// load the texture if the name is not empty
if (!m_materials->back().textureName.isEmpty())
loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().textureName);
if (!m_materials->back().tx0d.isEmpty())
loadTexture(m_materials->back().texture0, m_filepath + "/" + m_materials->back().tx0d);
}
// texture 1
else if (!strcmp("TX1D", it->name))
{
// get the texture name
m_file.seekg(it->position);
char* buffer = new char[it->size + 1];
*buffer = { 0 };
m_file.read(buffer, it->size);
m_materials->back().tx1d = buffer;
delete[] buffer;
// TODO: load texture to slot 1, need to change loadTexutre function
}
// texture 2
else if (!strcmp("TX2D", it->name))
{
// get the texture name
m_file.seekg(it->position);
char* buffer = new char[it->size + 1];
*buffer = { 0 };
m_file.read(buffer, it->size);
m_materials->back().tx2d = buffer;
delete[] buffer;
}
// texture 3
else if (!strcmp("TX3D", it->name))
{
// get the texture name
m_file.seekg(it->position);
char* buffer = new char[it->size + 1];
*buffer = { 0 };
m_file.read(buffer, it->size);
m_materials->back().tx3d = buffer;
delete[] buffer;
}
}
}
@@ -586,12 +623,12 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list<ChunkHeader*>
m_materials->push_back(Material());
m_materials->back().name = "Cloth Material";
m_materials->back().textureName = QString(buffer);
m_materials->back().tx0d = QString(buffer);
m_materials->back().shininess = 10;
if (!m_materials->back().textureName.isEmpty())
loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().textureName);
if (!m_materials->back().tx0d.isEmpty())
loadTexture(m_materials->back().texture0, m_filepath + "/" + m_materials->back().tx0d);
new_segment->textureIndex = m_materials->size() - 1;
@@ -687,7 +724,7 @@ void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath)
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().textureName += " *";
m_materials->back().tx0d += " *";
}
// Load image to OglTexture