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

@ -42,8 +42,12 @@ struct Model {
struct Material {
QString name;
QString textureName;
QOpenGLTexture* texture = Q_NULLPTR;
QString tx0d;
QString tx1d;
QString tx2d;
QString tx3d;
QOpenGLTexture* texture0 = Q_NULLPTR;
QOpenGLTexture* texture1 = Q_NULLPTR;
QVector4D specularColor = { 1.0, 1.0, 1.0, 1.0 };
QVector4D diffuseColor = { 1.0, 0.0, 0.0, 1.0 };
QVector4D ambientColor = { 1.0, 1.0, 1.0, 1.0 };
@ -132,7 +136,7 @@ public:
// f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
new_texture->setWrapMode(QOpenGLTexture::Repeat);
defMaterial->texture = new_texture;
defMaterial->texture0 = new_texture;
defMaterial->name = "Default Material";
return defMaterial;

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

View File

@ -1,6 +1,7 @@
#include "Header\MainWindow.h"
#include <QtWidgets/QApplication>
// TODO: add glow/emissive
int main(int argc, char *argv[])
{

View File

@ -13,11 +13,9 @@ Feel free to use my code the way you like. But remember i used some public libra
licence, too.
### To Do
- optional display bones, shadow, collision,...
- integrate into a software:
-> list all msh under a directory,
-> display shadows,
-> display colisions,
-> lights,
-> handle render flags,
- normal map,
- list all msh in a directory
- glow/emissive
- optional display bones, shadow, collision
- change pose
- animation