From 91488c55b2f44be1a4fc1b71c19b18005368667a Mon Sep 17 00:00:00 2001 From: Anakin Date: Sun, 22 Jan 2017 14:37:06 +0100 Subject: [PATCH] more information for the InfoWindow, set correct values for cloth material, enable specular map --- QtMeshViewer/Form Files/FileInfoWindow.ui | 8 +-- QtMeshViewer/Resources/about.txt | 4 +- QtMeshViewer/Resources/fshader.glsl | 7 ++- QtMeshViewer/Source/GeometryEngine.cpp | 5 +- QtMeshViewer/Source/MainWindow.cpp | 60 +++++++++++++++++++++-- QtMeshViewer/Source/MshFile.cpp | 38 ++++---------- 6 files changed, 82 insertions(+), 40 deletions(-) diff --git a/QtMeshViewer/Form Files/FileInfoWindow.ui b/QtMeshViewer/Form Files/FileInfoWindow.ui index 5e66054..912e070 100644 --- a/QtMeshViewer/Form Files/FileInfoWindow.ui +++ b/QtMeshViewer/Form Files/FileInfoWindow.ui @@ -6,8 +6,8 @@ 0 0 - 200 - 300 + 320 + 400 @@ -101,8 +101,8 @@ Triangles: - 0 0 - 180 - 222 + 300 + 322 diff --git a/QtMeshViewer/Resources/about.txt b/QtMeshViewer/Resources/about.txt index fb7b8cc..ffb3566 100644 --- a/QtMeshViewer/Resources/about.txt +++ b/QtMeshViewer/Resources/about.txt @@ -12,10 +12,12 @@ space - reset view L - set light to current position esc - close -using the X, Y, Z Button you can activate/deactivate the rotating directions +using the X, Y, Z buttons you can activate/deactivate the rotating directions. tipp: do round movement to rotate the object in z-direction, when all directions are acitvated +textures marked with a '*' couldn't be open. + =============================================================== Credits: ANDEWEGET diff --git a/QtMeshViewer/Resources/fshader.glsl b/QtMeshViewer/Resources/fshader.glsl index 3864f6c..43b1b17 100644 --- a/QtMeshViewer/Resources/fshader.glsl +++ b/QtMeshViewer/Resources/fshader.glsl @@ -12,6 +12,7 @@ uniform float materialShininess; uniform vec3 materialSpecularColor; uniform bool b_transparent; +uniform bool b_specular; uniform bool b_light; uniform struct Light { @@ -34,8 +35,6 @@ void main() vec4 surfaceColor = vec4(texture2D(texture, v_surfaceUV)); surfaceColor.rgb = pow(surfaceColor.rgb, vec3(2.2)); - if(!b_transparent) - surfaceColor.a = 1.0f; vec3 surfaceToLight; float attenuation; @@ -67,6 +66,8 @@ void main() float specularCoefficient = 0.0; if(diffuseCoefficient > 0.0) specularCoefficient = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normalWorld))), materialShininess); + if(b_specular) + materialSpecularColor = vec3(surfaceColor.a); vec3 specular = specularCoefficient * materialSpecularColor * light.intensities; // linear color before gamma correction) @@ -74,6 +75,8 @@ void main() // final color after gama correction vec3 gamma = vec3(1.0/2.2); + if(!b_transparent) + surfaceColor.a = 1.0f; gl_FragColor = vec4(pow(linearColor, gamma), surfaceColor.a); } else diff --git a/QtMeshViewer/Source/GeometryEngine.cpp b/QtMeshViewer/Source/GeometryEngine.cpp index 75835db..7dddbb6 100644 --- a/QtMeshViewer/Source/GeometryEngine.cpp +++ b/QtMeshViewer/Source/GeometryEngine.cpp @@ -177,6 +177,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe) for (auto& it : m_drawList) { bool tmp_transparent(false); + bool tmp_specular(false); float shininess; QVector3D specularColor; @@ -185,6 +186,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe) { m_materials->at(it.textureIndex).texture->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; specularColor = m_materials->at(it.textureIndex).specularColor.toVector3D(); } @@ -199,8 +201,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe) // Set normal matrix program->setUniformValue("n_matrix", (normMatrix * it.modelMatrix).normalMatrix()); - // decide if this is transparent + // set some more values program->setUniformValue("b_transparent", tmp_transparent); + program->setUniformValue("b_specular", tmp_specular); // set some material attributes program->setUniformValue("materialShininess", shininess); diff --git a/QtMeshViewer/Source/MainWindow.cpp b/QtMeshViewer/Source/MainWindow.cpp index eb8974c..ea4f651 100644 --- a/QtMeshViewer/Source/MainWindow.cpp +++ b/QtMeshViewer/Source/MainWindow.cpp @@ -210,16 +210,68 @@ void MainWindow::setFileInfo(QString name, QVector* materials, int ver m_fileInfo += QByteArray::number(triangle); m_fileInfo += ""; - int count(0); //TODO: mark not opened textures //TODO: add more information for (auto& it : *materials) { - m_fileInfo += "Material "; - m_fileInfo += QByteArray::number(count++); - m_fileInfo += " - "; m_fileInfo += it.name; m_fileInfo += "\n"; + + m_fileInfo += "TX0D:\t\t"; + if (it.texture == NULL) + m_fileInfo += "-"; + m_fileInfo += it.textureName; + m_fileInfo += "\n"; + + m_fileInfo += "Flags:\t\t"; + for (int i = 0; i < 8; i++) + { + if (it.flags[i]) + m_fileInfo += "1"; + else + m_fileInfo += "0"; + } + m_fileInfo += "\n"; + + m_fileInfo += "Rendertype:\t-"; + //TODO: rendertype + m_fileInfo += "\n"; + + m_fileInfo += "Shininess:\t"; + m_fileInfo += QByteArray::number(it.shininess); + m_fileInfo += "\n"; + + m_fileInfo += "Diffusecolor:\tR: "; + m_fileInfo += QByteArray::number(it.diffuseColor.x()); + m_fileInfo += "\tG: "; + m_fileInfo += QByteArray::number(it.diffuseColor.y()); + m_fileInfo += "\tB: "; + m_fileInfo += QByteArray::number(it.diffuseColor.z()); + m_fileInfo += "\tA: "; + m_fileInfo += QByteArray::number(it.diffuseColor.w()); + m_fileInfo += "\n"; + + m_fileInfo += "Ambientcolor:\tR: "; + m_fileInfo += QByteArray::number(it.ambientColor.x()); + m_fileInfo += "\tG: "; + m_fileInfo += QByteArray::number(it.ambientColor.y()); + m_fileInfo += "\tB: "; + m_fileInfo += QByteArray::number(it.ambientColor.z()); + m_fileInfo += "\tA: "; + m_fileInfo += QByteArray::number(it.ambientColor.w()); + m_fileInfo += "\n"; + + m_fileInfo += "Specularcolor:\tR: "; + m_fileInfo += QByteArray::number(it.specularColor.x()); + m_fileInfo += "\tG: "; + m_fileInfo += QByteArray::number(it.specularColor.y()); + m_fileInfo += " \tB: "; + m_fileInfo += QByteArray::number(it.specularColor.z()); + m_fileInfo += " \tA: "; + m_fileInfo += QByteArray::number(it.specularColor.w()); + m_fileInfo += "\n"; + + m_fileInfo += "-----------------------------------------------------------------\n"; } m_output->setText(m_fileInfo.left(m_fileInfo.indexOf(""))); diff --git a/QtMeshViewer/Source/MshFile.cpp b/QtMeshViewer/Source/MshFile.cpp index 78ff108..2ea6893 100644 --- a/QtMeshViewer/Source/MshFile.cpp +++ b/QtMeshViewer/Source/MshFile.cpp @@ -572,7 +572,6 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list for (auto& it : chunkList) { // texture name - //TODO: change this if (!strcmp("CTEX", it->name)) { // read the texture name @@ -581,26 +580,17 @@ void MshFile::analyseClthChunks(Model * dataDestination, std::list *buffer = { 0 }; m_file.read(buffer, it->size); - // search if it is already known - bool tmp_found(false); - for (unsigned int index = 0; index < m_materials->size(); index++) - { - if (m_materials->at(index).name == QString(buffer)) - { - tmp_found = true; - new_segment->textureIndex = index; - break; - } - } + + m_materials->push_back(Material()); + m_materials->back().name = "Cloth Material"; + m_materials->back().textureName = QString(buffer); - if(!tmp_found) - { - m_materials->push_back(Material()); - m_materials->back().name = QString(buffer); + m_materials->back().shininess = 10; - loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().name); - new_segment->textureIndex = m_materials->size() - 1; - } + if (!m_materials->back().textureName.isEmpty()) + loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().textureName); + + new_segment->textureIndex = m_materials->size() - 1; delete[] buffer; } @@ -688,21 +678,13 @@ void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath) bool loadSuccess(false); QImage img = loadTga(filepath, loadSuccess); - if (filepath.isEmpty()) - { - loadSuccess = true; - img = QImage(1, 1, QImage::Format_RGB32); - img.fill(Qt::red); - } - else - img = loadTga(filepath, loadSuccess); - if (!loadSuccess) { emit sendMessage("WARNING: texture not found or corrupted: " + m_materials->back().name, 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().textureName += " *"; } // Load image to OglTexture