read tx1d tx2d tx3d texture names and print to info window
This commit is contained in:
parent
2ed9e475ce
commit
b2df84eb4c
|
@ -42,8 +42,12 @@ struct Model {
|
||||||
|
|
||||||
struct Material {
|
struct Material {
|
||||||
QString name;
|
QString name;
|
||||||
QString textureName;
|
QString tx0d;
|
||||||
QOpenGLTexture* texture = Q_NULLPTR;
|
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 specularColor = { 1.0, 1.0, 1.0, 1.0 };
|
||||||
QVector4D diffuseColor = { 1.0, 0.0, 0.0, 1.0 };
|
QVector4D diffuseColor = { 1.0, 0.0, 0.0, 1.0 };
|
||||||
QVector4D ambientColor = { 1.0, 1.0, 1.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)
|
// f.ex. texture coordinate (1.1, 1.2) is same as (0.1, 0.2)
|
||||||
new_texture->setWrapMode(QOpenGLTexture::Repeat);
|
new_texture->setWrapMode(QOpenGLTexture::Repeat);
|
||||||
|
|
||||||
defMaterial->texture = new_texture;
|
defMaterial->texture0 = new_texture;
|
||||||
defMaterial->name = "Default Material";
|
defMaterial->name = "Default Material";
|
||||||
|
|
||||||
return defMaterial;
|
return defMaterial;
|
||||||
|
|
|
@ -21,7 +21,7 @@ GeometryEngine::GeometryEngine(QObject *parent)
|
||||||
GeometryEngine::~GeometryEngine()
|
GeometryEngine::~GeometryEngine()
|
||||||
{
|
{
|
||||||
clearData();
|
clearData();
|
||||||
delete m_defaultMaterial->texture;
|
delete m_defaultMaterial->texture0;
|
||||||
delete m_defaultMaterial;
|
delete m_defaultMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ 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.texture;
|
delete it.texture0;
|
||||||
m_materials->clear();
|
m_materials->clear();
|
||||||
delete m_materials;
|
delete m_materials;
|
||||||
}
|
}
|
||||||
|
@ -182,9 +182,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
|
||||||
QVector3D specularColor;
|
QVector3D specularColor;
|
||||||
|
|
||||||
// bind the correct texture
|
// 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_transparent = m_materials->at(it.textureIndex).transparent;
|
||||||
tmp_specular = m_materials->at(it.textureIndex).flags[7];
|
tmp_specular = m_materials->at(it.textureIndex).flags[7];
|
||||||
shininess = m_materials->at(it.textureIndex).shininess;
|
shininess = m_materials->at(it.textureIndex).shininess;
|
||||||
|
@ -192,7 +192,7 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_defaultMaterial->texture->bind();
|
m_defaultMaterial->texture0->bind();
|
||||||
tmp_transparent = m_defaultMaterial->transparent;
|
tmp_transparent = m_defaultMaterial->transparent;
|
||||||
}
|
}
|
||||||
// Set model matrix
|
// Set model matrix
|
||||||
|
|
|
@ -210,17 +210,37 @@ void MainWindow::setFileInfo(QString name, QVector<Material>* materials, int ver
|
||||||
m_fileInfo += QByteArray::number(triangle);
|
m_fileInfo += QByteArray::number(triangle);
|
||||||
m_fileInfo += "<detail>";
|
m_fileInfo += "<detail>";
|
||||||
|
|
||||||
//TODO: mark not opened textures
|
|
||||||
//TODO: add more information
|
|
||||||
for (auto& it : *materials)
|
for (auto& it : *materials)
|
||||||
{
|
{
|
||||||
m_fileInfo += it.name;
|
m_fileInfo += it.name;
|
||||||
m_fileInfo += "\n";
|
m_fileInfo += "\n";
|
||||||
|
|
||||||
m_fileInfo += "TX0D:\t\t";
|
m_fileInfo += "TX0D:\t\t";
|
||||||
if (it.texture == NULL)
|
if (it.tx0d.isEmpty())
|
||||||
m_fileInfo += "-";
|
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 += "\n";
|
||||||
|
|
||||||
m_fileInfo += "Flags:\t\t";
|
m_fileInfo += "Flags:\t\t";
|
||||||
|
|
|
@ -249,7 +249,6 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||||
m_file.read(F2V(m_materials->back().shininess), sizeof(float));
|
m_file.read(F2V(m_materials->back().shininess), sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: evaluate specular, gloss,.. and save values
|
|
||||||
// attributes
|
// attributes
|
||||||
else if (!strcmp("ATRB", it->name))
|
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))
|
else if (!strcmp("TX0D", it->name))
|
||||||
{
|
{
|
||||||
// get the texture name
|
// get the texture name
|
||||||
|
@ -289,12 +288,50 @@ void MshFile::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
|
||||||
char* buffer = new char[it->size + 1];
|
char* buffer = new char[it->size + 1];
|
||||||
*buffer = { 0 };
|
*buffer = { 0 };
|
||||||
m_file.read(buffer, it->size);
|
m_file.read(buffer, it->size);
|
||||||
m_materials->back().textureName = buffer;
|
m_materials->back().tx0d = buffer;
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
|
||||||
// load the texture if the name is not empty
|
// load the texture if the name is not empty
|
||||||
if (!m_materials->back().textureName.isEmpty())
|
if (!m_materials->back().tx0d.isEmpty())
|
||||||
loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().textureName);
|
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->push_back(Material());
|
||||||
m_materials->back().name = "Cloth Material";
|
m_materials->back().name = "Cloth Material";
|
||||||
m_materials->back().textureName = QString(buffer);
|
m_materials->back().tx0d = QString(buffer);
|
||||||
|
|
||||||
m_materials->back().shininess = 10;
|
m_materials->back().shininess = 10;
|
||||||
|
|
||||||
if (!m_materials->back().textureName.isEmpty())
|
if (!m_materials->back().tx0d.isEmpty())
|
||||||
loadTexture(m_materials->back().texture, m_filepath + "/" + m_materials->back().textureName);
|
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;
|
||||||
|
|
||||||
|
@ -687,7 +724,7 @@ void MshFile::loadTexture(QOpenGLTexture *& destination, QString filepath)
|
||||||
|
|
||||||
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().textureName += " *";
|
m_materials->back().tx0d += " *";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load image to OglTexture
|
// Load image to OglTexture
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "Header\MainWindow.h"
|
#include "Header\MainWindow.h"
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
|
// TODO: add glow/emissive
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
14
README.md
14
README.md
|
@ -13,11 +13,9 @@ Feel free to use my code the way you like. But remember i used some public libra
|
||||||
licence, too.
|
licence, too.
|
||||||
|
|
||||||
### To Do
|
### To Do
|
||||||
- optional display bones, shadow, collision,...
|
- normal map,
|
||||||
- integrate into a software:
|
- list all msh in a directory
|
||||||
-> list all msh under a directory,
|
- glow/emissive
|
||||||
-> display shadows,
|
- optional display bones, shadow, collision
|
||||||
-> display colisions,
|
- change pose
|
||||||
-> lights,
|
- animation
|
||||||
-> handle render flags,
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue